Product Name Prefills Contact Form
Following on from earlier Magento blog posts where I’ve described how some clients may not want to actually sell their products online, but rather use the architecture of Magento as a CMS – there’s a very simple way of converting these product pages into online enquiries. Trust me, I’m not flogging a dead horse with all this talk of using Magento, but not as a shop. It really can work! A neat touch is to pre-fill the existing Magento contact form with details about the product that you’re on – this could include the product name, price and any attributes you could care to mention. Here’s how to do it:
Open your product view page: app/design/frontend/base/modern/template/product/view.phtml
<form method="post" action="/contacts"> <input name="productname" type="hidden" value="<?php echo $_helper->productAttribute($_product, $this->htmlEscape($_product->getName()), 'name') ?>" /> <input type="image" src="/images/enquire.gif" /> </form>
If you add something similar to the form above, you’ll have hidden fields pre-filled with the Product Name data, and a new ‘Enquire Online’ button. Also notice that the form’s action value points to the contact us page that Magento creates for you.
Now if you open the contacts page: app/design/frontend/base/default/template/contacts/form.phtml
<label for="subject"><?php echo $this->__('Subject') ?></label><br />
<input name="subject" id="subject" title="<?php echo $this->__('Subject') ?>" value="<?php if (isset($_POST["productname"])) { echo $_POST["productname"]; } ?>" type="text"/>
</div>
In this instance I have entered the Product Name into the ‘Subject’ field of the contact form, but some very important PHP is involved. The “if(isset” conditional is essential in not breaking your contact form in circumstances where people visit your contact page without going through the product first. If you apply the exact same rules to any data on the product page you can create a very seamless and user-friendly online enquiries process.
Who know, you then might get to use Magento as an actual ecommerce website design shop!!

May 1st, 2010
Can you please explain this instruction step by step, because i tried it my self and it wont work.
May 18th, 2010
Thanks for this, works excellently, the only problem I had was, at first I accidentally copied the form code into another form, which seemed to just confuse the action, making it think you were still adding the product to the cart.
This is helpful, even if you do still want your customers to be able to purchase as well.
May 19th, 2010
Jess, I should probably mention that you want this code to be outside of the main shopping cart form, otherwise it won’t work. The code I have provided has worked without problem for me – send me the source code of the product and contact pages and I’ll take a look.