6

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.

10

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.

  • Where do I place this {{block type="core/template" template="path/to/template.phtml"}}. Can you please kindly verify ? Thanks – iori Jan 13 '15 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. – Marius Jan 14 '15 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"}}
  • 1
    For future googlers: see my comment to @stifboy as to why this would be a potential CVE/PCI issue for EE shops. – philwinkle Mar 4 '14 at 15:27
  • Where do I place this {{block type="core/template" template="path/to/template.phtml"}}. Can you please kindly verify ? Thanks – iori Jan 13 '15 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"}}
  • 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. – philwinkle Mar 4 '14 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.