I have created a template in which I need to place the "contact us" form.

I can currently think of two ways to do this:

echo $this->getLayout()->createBlock('customer/form_edit')->setTemplate('contacts/form.phtml')->toHtml();


Create a cms block with an id "contact_form"

and content:

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

then call it my template with:

echo $this->getLayout()->createBlock('cms/block')->setBlockId('contact_form')->toHtml();

What would be the difference between those two approaches, and is there a better one?

1 Answer 1


If you have already a template the do call it like:

echo $this->getLayout()->createBlock('core/template')->setFormAction($this->getUrl('contacts/index/post', array('_secure'=>true)))->setTemplate('contacts/form.phtml')->toHtml();

Because your 2nd way it like adding additional step to call same result. While 1st way does have wrong block because you don't need that, you just need to call block core/template and just set FormAction to it.

  • Amazing, exactly what I was looking for. I wasn't aware of setFormAction. Sep 22, 2018 at 11:35
  • But you're missing a bracket after "true";) Sep 22, 2018 at 11:36

Your Answer

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

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