Question

I'm new in magento and I wonder how to create a form in a CMS page and receive the information by email.

I did some research on the internet but I did not find explicit answers.

Was it helpful?

Solution

First you login Magento admin -> CMS -> Pages

Select your page and input your HTML code as you normally would on any other information you include the page, then select Content tab and add it.

The below lines to add your cms -> page:

{{block type="core/template" name="contactForm" form_action="{{store direct_url='contacts'}}/index/post" template="contacts/form.phtml"}}

OTHER TIPS

@mbalparda answer is right, but it partially answer the question. In short, it gives you a perfect hint on how you can include a contact-form block inside cms page. But what about adding a custom form in CMS Page? For this, you can refer below answer.

Step 1 : Create a form

First, you need to create a form that you need to include in CMS Pages. In its simplest form, you should define a new form template for this.

File : app\design\frontend\[package]\[theme]\template\custom\yourform.phtml

<form action="some/action/" name="form-name" id="form-id" >
   <!-- form inputs come here -->
</form>

Step 2 : Include Your Custom Form in CMS Page

Go to the CMS Page content section and add below content.

 {{block type="core/template" template="custom/yourform.phtml"}}

We are taking the advantage of block-directives here. You can insert any block in CMS page like this. This will use your custom form template and render its content inside CMS Page.

Above answer is right but there are some suggestion for this case.

1.Change form action post url:

Change the action form /contacts/index/post to custom url like /contacts/index/custompost.Because of after form submitting.Custom will redirect to contacts/index/index instead of custom cms page because of code at postAction function of Mage_Contacts_IndexController ($this->_redirect('*/*/');).

So,you need to override Mage_Contacts Indexcontroller and will add a new action custompostAction .

Copy all code of postAction function to custompostAction and just change

   $this->_redirect('*/*/');
      to

      $backUrl=Mage::getUrl().'cmsPageInd';
      $this->getResponse()->setRedirect($backUrl);

Call form block from Design tab:

Instead call of form from Content,call the code at Design tab(Layout Update XML)

<reference name="content">
  <block  type="core/template" name="CmscontactForm" form_action="/contacts/index/custompost"/ >
</reference>

Use

<!– CONTACT FORM –>
{{block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"}}
<!– END OF CONTACT FORM –>

in any CMS page. See this page for some more info.

  1. First login in your magento admin
  2. Go to your CMS> Manage Pages interface
  3. Once there, input your HTML as you normally would on any other page
  4. Once you are happy with HTML part, add this lines:

{{block type=”core/template” name=”contactForm” form_action=”{{store direct_url=”contacts”}}/index/post” template=”contacts/form.phtml”}}

Let me know if you have any query

For what it's worth - I'm using Magento 2 and the answers here are for Magento 1.x.

This is the shortcode syntax that worked for me in Magento 2:

{{block class="Magento\Framework\View\Element\Template" name="contactForm" form_action="/contacts/index/post" template="Magento_Contact::form.phtml"}}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top