Skip to main content

Embed Form in .phtml Template

You can call web-form in any .phtml file using following example:

Default form widget

<?php
echo $this->getLayout()->createBlock(
'MageMe\WebForms\Block\Form',
null,
['data'=>[
'form_id' => 1
]]
)->toHtml();
?>

form_id - is actual ID of the form.

Button with the form in popup

Use the following code to insert the button with the form in popup:

<?php
echo $this->getLayout()->createBlock(
'MageMe\WebForms\Block\Widget\Button',
null,
['data' => [
'form_id' => 1,
'template' => 'button/default.phtml',
'button_text' => __('Contact Us'),
]]
)->toHtml();
?>

form_id - is actual ID of the form.

template - form template which can have following values:

  • button/default.phtml - default template

button_text - text on the button.