2

I've created a custom_form.phtml file, and I've place it alongside the normal form.phtml.

In a CMS Page, I've then added this block:

{{block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/custom_form.phtml"}}

...but now I'd like this form to use a certain Transactional template I made accordingly, named "Custom Transactional", and created under System > Transactional Mails.

How could I relate both the .phtml and the Transactional template with the multiple fields like {{var data.address}} {{var data.country}} {{var data.postcode}}, etc?

Many thanks for any input.

1 Answer 1

4

If you look at the contacts controller used in the form action, you will find that

  1. the transactional template is taken directly from the configuration
  2. all POST data is passed to the template (as template variable data), so that you can add any additional fields to the form template and use them in the email template. But validation is hard coded for "name", "comment", "email" and "hideit".

So, if you need a completely different email template or additional/changed input validation, your best bet is to create a custom controller with a modified copy of the postAction of Mage_Contacts_IndexController.

But there is another solution that is a bit limited but without any custom code involved:

  • create a hidden input that determines the type of the form. It could be just <input type="hidden" name="custom" value="1" />.
  • in the contact transactional email template, use the if directive to show different content based on the form type:

    {{if data.custom}}
        ... custom contact form email ...
    {{else}}
        ... standard contact form email ...
    {{/if}}
    
2
  • 1
    Excellent, it worked! I added the hidden field into the .phtml file, uploaded it by FTP, then went to System > Transactional Mails, created a new template, loaded the default Contact Form in it (very important step), and added the conditionals with my custom fields. Finally I went to System > Config > Contacts and selected that newly created template as the main one. Thanks for the help!
    – Peanuts
    Aug 23, 2015 at 15:51
  • Brilliant piece of advice, Can confirm it works on Mag 1.9.3
    – A. Lal
    Jul 25, 2019 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.