7

I'm new working with Magento, and I was wondering if there's any way I can create a CMS page that uses PHP code. I mean,the page I need to create is something like an About Us, with a short description and a pretty simple contact form. Now, I tried to create it in the CMS section but it only allows me to use HTML code.

Am I doing it the wrong way? What would be the right way? Create a Module? A Block with the Form?

Any suggestions are truly appreciated.

Thanks.

3 Answers 3

12

The cms pages do not allow php code.
You can create a template to display your content and you can include it in the page like this:

{{block type="core/template" template="path/to/template.phtml"}}

But in your case you want to have a form and you need also something to handle the form submission.
For this I recommend creating a module.
Here is a small example that does exactly that. It shows you how to create a module with a form in it and handle the form submission.

2
  • Where do I place this {{block type="core/template" template="path/to/template.phtml"}}. Can you please kindly verify ? Thanks Commented Jan 13, 2015 at 18:41
  • 1
    @evoque2015 You should add it in the content of the cms page you need. Edit the page in the backend. Cms->Pages and click on the Content tab. Commented Jan 14, 2015 at 7:16
2

You can easily add default Magento contact form to your CMS page by adding the following shortcode:

{{block type="core/template" name="contact" form_action="/contacts/index/post" template="contacts/form.phtml"}}
2
  • 1
    For future googlers: see my comment to @stifboy as to why this would be a potential CVE/PCI issue for EE shops. Commented Mar 4, 2014 at 15:27
  • Where do I place this {{block type="core/template" template="path/to/template.phtml"}}. Can you please kindly verify ? Thanks Commented Jan 13, 2015 at 18:41
2

Simply use this to add a contact form on your magento cms page

{{block type="core/template" name="contact" form_action="/contacts/index/post" template="contacts/form.phtml"}}
1
  • 3
    Great suggestion - but if the OP has a full page cache or is using EE this will cause the form fields to (incorrectly) cache previous form posts, causing an information leak vulnerability. This is because Magento EE FPC will cache all CMS pages by default. Commented Mar 4, 2014 at 15:26

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.