Add fields to contact form

Last modified by iZilla_Pod on Thu, June 24, 2010 17:13
Source|Old Revisions  

This is an old revision of the document!


Step One: Modify the (interface)/(theme)/template/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="test" 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.

You’re 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.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs