The form object is used inside the form tag. It contains the attributes of its parent form.
form.address1
Returns the first address line of the address. Only for form tags with the "address" parameter.
form.address2
Returns the second address line of the address, if it exists. Only for form tags with the "address" parameter.
form.author
Returns the name of the author of the blog article comment. Only for form tags with the "article" parameter.
form.body
Returns the content of the blog article comment. Only for form tags with the "article" parameter.
form.city
Returns the city of the address. Only for form tags with the "address" parameter.
form.company
Returns the company name of the address, if it exists. Only for form tags with the "address" parameter.
form.country
Returns the country of the address. Only for form tags with the "address" parameter.
form.email
Returns the email address of the author of the blog article comment. Only for form tags with the "article" parameter.
form.errors
Returns an array of strings if the form was not submitted successfully. The returned strings depend on which fields the form type requires. Possible values:
author: for required name fields, for example blog commentsbody: for message text, for example in a contact formemail: for required email fieldspassword: for required password fieldsform: a general error used when no more specific error applies
{% for error in form.errors %}
{{ error }}
{% endfor %}
<!-- if the Name field was left empty by the user -->
author
Apply the default_errors filter to form.errors to output default error messages without looping through the array.
{% if form.errors %}
{{ form.errors | default_errors }}
{% endif %}
Please enter a valid email address.
form messages and translated fields
Loop through the form.errors.messages and form.errors.translated_fields arrays to get more information about the returned form.errors. Use an error from form.errors as key to target a specific element of either array.
The messages array contains the translated error messages for the values in form.errors.
The translated_fields array contains the translated field names for the values in form.errors.
<ul>
{% for field in form.errors %}
<li> {% if field == 'form' %} {{ form.errors.messages[field] }} {% else %} {{ form.errors.translated_fields[field] }} - {{ form.errors.messages[field] }} {% endif %} </li>
{% endfor %}
</ul>
<ul>
<li>We have sent you an email. Please click the link in it to confirm your email address.</li>
<li>Password - Please enter a valid password.</li>
</ul>
form.first_name
Returns the first name of the address. Only for form tags with the "address" parameter.
form.id
Returns the ID (unique identifier) of the form.
form.last_name
Returns the last name of the address. Only for form tags with the "address" parameter.
form.password_needed
Only used for form tags with the "customerlogin" parameter. `form.passwordneededalways returnstrue`.
form.phone
Returns the phone number of the address, if it exists. Only for form tags with the "address" parameter.
form.posted_successfully?
Returns true if the form was submitted successfully, false if it contained errors. All forms except the address form set this property. The address form is always submitted successfully.
{% if form.posted_successfully? %}
Comment submitted successfully!
{% else %}
{{ form.errors | default_errors }}
{% endif %}
form.province
Returns the province or state of the address. Only for form tags with the "address" parameter.
{{ form.city }}, {{ form.province }}
Koblenz, Rhineland-Palatinate
form.setasdefault_checkbox
Outputs an HTML checkbox that submits the current form as the customer's default address. Only for form tags with the "address" parameter.
{{ form.set_as_default_checkbox }}
<input type="checkbox" id="address_default_address_12345678" name="address[default]" value="1">
form.zip
Returns the ZIP or postal code of the address. Only for form tags with the "address" parameter.