Magento: Add a custom field to the Contact Us Form

Update the Contact Us form template

Firstly you need to edit the contact form template.
If using the default theme, this code will be located in

Add the following markup to the template in the desired position:

<div class="input-box">
    <label for="where-hear"><?php echo Mage::helper('contacts')->__('Where did you hear about us?') ?> <span class="required">*</span></label><br />
    <select name="where-hear" id="where-hear" style="width:300px" class="required-entry">
        <option value="" selected>Please select...</option>
        <option value="Google">Google</option>
        <option value="Magazine">Magazine</option>
        <option value="Word of Mouth">Word of Mouth</option>
        <option value="Other">Other</option>

Note the use of class=”required-entry” on the select element.. This tells the default javascript validation that this field is required. If the user tries to submit the form without choosing an option, then it will throw an error and highlight the field.

So that takes care of the form, now you need to set up a custom email template that includes the new field.

Create a custom transactional email template

Navigate to the following screen in your Magento admin:
System > Transactional Emails

  1. Click Add New Template
  2. In the top block (Load default template), select “Contact Form” from the drop box and click Load Template
  3. In the Template Information block, set the Template Name to “Custom Contact Form”
  4. In the Template Content field, add the following line where you want it to appear in the email:
    Where did you hear about us?: {{var data.where-hear}}

Assign the custom email template

Navigate to the following screen in your Magento admin:
System > Configuration > General > Contacts

In the Email Options block, set the Email Template to “Custom Contact Form”.

Click Save Config and you’re all done.


how to use increment quantity in magento

// Your code here

var currentVal = parseInt(jQuery(this).prev(“.qty”).val());

if (!currentVal || currentVal==”” || currentVal == “NaN”) currentVal = 0;

jQuery(this).prev(“.qty”).val(currentVal + 1);

var currentVal = parseInt(jQuery(this).next(“.qty”).val());
if (currentVal == “NaN”) currentVal = 0;
if (currentVal > 0)
jQuery(this).next(“.qty”).val(currentVal – 1);

getProduct(); ?>
__(‘Add to Cart’); ?>
isSaleable()): ?>

isGrouped()): ?>

<input type="text" name="qty" id="qty" maxlength="12" value="getMinimalQty($_product) ?>” title=”__(‘Qty’) ?>” class=”input-text qty” />

<button type="button" title="” class=”add-to-cart ” onclick=”productAddToCartForm.submit(this)”>
getChildHtml(”, true, true) ?>

numeric value validation

   <SCRIPT language=Javascript>
      function isNumberKey(evt)
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      <INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar">