Call-back icon  Sales: Call 877.832.5289 (N America)|310.295.4144 (International)

Magento

eCommerce Software for Online Growth

Add fields to contact form

Last modified by mk30 on Mon, August 4, 2008 15:33
Source|Old Revisions  

Step One: Modify the (interface)/(theme)/templates/contacts/form.phtml file.

Say we would like to add a field called ‘Test’ in between e-mail and telephone on the default field.

Here is the current code:

  1. <div class="input-box">
  2.                     <label for="email"><?php echo $this->__('Email') ?> <span class="required">*</span></label><br />
  3.                     <input name="email" id="email" title="<?php echo $this->__('Email') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserEmail()) ?>" class="required-entry input-text validate-email" type="text"/>
  4.                 </div>
  5.  
  6.                 <div class="clear"></div>
  7.  
  8.                 <div class="input-box">
  9.                     <label for="telephone"><?php echo $this->__('Telephone') ?></label><br />
  10.                     <input name="telephone" id="telephone" title="<?php echo $this->__('Telephone') ?>" value="" class="input-text" type="text"/>
  11.                 </div>

Here is the new field:

  1. <div class="input-box">
  2.                     <label for="email"><?php echo $this->__('Email') ?> <span class="required">*</span></label><br />
  3.                     <input name="email" id="email" title="<?php echo $this->__('Email') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserEmail()) ?>" class="required-entry input-text validate-email" type="text"/>
  4.                 </div>
  5.  
  6.                 <div class="clear"></div>
  7.  
  8.                 <div class="input-box">
  9.                     <label for="test"><?php echo $this->__('Test') ?></label><br />
  10.                     <input name="test" id="telephone" title="<?php echo $this->__('Test') ?>" value="" class="input-text" type="text"/>
  11.                 </div>
  12.  
  13.                 <div class="input-box">
  14.                     <label for="telephone"><?php echo $this->__('Telephone') ?></label><br />
  15.                     <input name="telephone" id="telephone" title="<?php echo $this->__('Telephone') ?>" value="" class="input-text" type="text"/>
  16.                 </div>

I literally just copied the telephone input code and changed the titles. The reason this is important is that it doesn’t matter to Magento what is here because the function on the backend is written such that it will take whatever values are posted to it and send that out via the transactional e-mail form that you create.

Step Two: Create the new Transactional E-Mail form.

1) Go to System→Transactional E-mails in the Magento Admin section. 2) Click ‘Add New Template’ 3) From the ‘Template’ dropdown box select ‘Contact Form’ 4) Click ‘Load Template’ 5) Under template content you will see:

  1. Name: {{var data.name}}
  2. E-mail: {{var data.email}}
  3. Telephone: {{var data.telephone}}
  4. Comment: {{var data.comment}}

Add your new field in between E-mail and Telephone:

  1. Name: {{var data.name}}
  2. E-mail: {{var data.email}}
  3. Test: {{var data.test}}
  4. Telephone: {{var data.telephone}}
  5. Comment: {{var data.comment}}

6) Enter a name to save the new form under in the input area of ‘Template Name’ and click ‘Save Template’ 7) Go to System→Configuration and select ‘Contacts’ on the left hand menu. 8) Select your newly saved template in the ‘Email Template’ dropdown box.

Your good to go!!

Note: The var_data.something will take whatever is the id value of the input field on your form and output it here in the e-mail.




 

Popular Wiki Tags  |  View all

 module   routes   list   data accessing   resource   backend   api   action   mysql4   controller   getModel   model   php   custom attributes   attribute 

Professional Services from the Magento Team

Professional Installation from the Magento Team

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs
Sales: Call 877.832.5289 (North America) 310.295.4144 (International)
© Copyright 2008 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
50166 users|583 users currently online|102322 forum posts