Magento contact form in CMS page
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.
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>