form Tag
The form
tag allows you to add submission forms to collect site visitor input from your website.
Usage
You must include the forms_script()
call on your page once to use this feature.
Example
theme/templates/pages/item.html.twig
{{ forms_script() }}
{% form "my_form_id" %}
<label for="first_name">First Name</label>
<input type="text" name="first_name" id="first_name" required=”required” />
<label for="middle_name">Middle Name</label>
<input type="text" name="middle_name" id="middle_name" required=”required” />
<label for="phone">Phone</label>
<input type="text" name="phone" id="phone" />
{% endform %}
Handling success and error states
Submissions made via the form tag return success and error messages. You can render these messages to the page using the following keys on the response
variable:
{{ response.success.form }}
{{ response.errors.form }}
Customer data support
If you want to automatically integrate with the customer creation and messenger system, there is native support for input fields named phone
and email
.
Additional form settings
Additional form settings may be configured inside of a single settings file named forms.json
. By default, all notifications for form submissions are sent to the email address of the owning account, but this can be overridden on a per form basis as seen below:
{
"forms": {
"my_form_id": {
"notification_email": "johndoe@squareup.com"
}
}
}