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(
'VladimirPopov\WebForms\Block\Form',
null,
['data'=>[
'webform_id' => 1,
'template' => 'VladimirPopov_WebForms::webforms/form/default.phtml',
'scroll_to' => '0',
'after_submission_form' => '0',
'async_load' => '1',
]]
)->toHtml();
?>
webform_id - is actual ID of the form.
template - form template which can have following values:
- webforms/form/default.phtml - default template
- webforms/form/multistep.phtml - multi-step template
- webforms/form/sidebar.phtm - compact sidebar template very similar to default
after_submission_form - show form after submission and display success text in popup.
scroll_to - scroll to the top of the success message after form submission.
async_load - load form asynchronously to bypass any caching. This is recommended when you pre-fill fields with customer data.
Button with the form in popup
Use the following code to insert the button with the form in popup:
<?php
echo $this->getLayout()->createBlock(
'VladimirPopov\WebForms\Block\Widget\Button',
null,
['data' => [
'webform_id' => 1,
'template' => 'webforms/button/default.phtml',
'form_template' => 'webforms/form/default.phtml',
'button_text' => __('Contact Us'),
'scroll_to' => 0,
'after_submission_form' => 0,
'async_load' => 1,
]]
)->toHtml();
?>
webform_id - is actual ID of the form.
template - form template which can have following values:
- webforms/button/default.phtml - default template
form_template - form template which can have following values:
- webforms/form/default.phtml - default template
- webforms/form/multistep.phtml - multi-step template
- webforms/form/sidebar.phtm - compact sidebar template very similar to default
after_submission_form - show form after submission and display success text in popup.
button_text - text on the button.
scroll_to - scroll to the top of the success message after form submission.
async_load - load form asynchronously to bypass any caching. This is recommended when you pre-fill fields with customer data.
Please note that template and form_template have different values. In case of the button the first one renders the button with popup script, the second one - form.