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.
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"}}
@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.
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>
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.
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);
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.
{{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"}}