Question

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.

Was it helpful?

Solution

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}}
    
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top