The form object
The form
object is used within the form tag. It contains attributes of its parent form.
form.address1
Returns the first address line associated with the address. Exclusive to form
tags with the "address" parameter.
form.address2
Returns the second address line associated with the address, if it exists. Exclusive to form
tags with the "address" parameter.
form.author
Returns the name of the author of the blog article comment. Exclusive to form
tags with the "article" parameter.
form.body
Returns the content of the blog article comment. Exclusive to form
tags with the "article" parameter.
form.city
Returns the city associated with the address. Exclusive to form
tags with the "address" parameter.
form.company
Returns the company name associated with the address, if it exists. Exclusive to form
tags with the "address" parameter.
form.country
Returns the country associated with the address. Exclusive to form
tags with the "address" parameter.
form.email
Returns the email of the blog article comment's author. Exclusive to form
tags with the "article" parameter.
form.errors
Returns an array of strings if the form was not submitted successfully. The strings returned depend on which fields are required for the form
type. Possible values are:
author
: for required name fields, such as blog commentsbody
: for text content of messages, such as a contact formemail
: for required email fieldspassword
: for required password fieldsform
: used as a general error in cases where a more specific error cannot be provided
Input
{% for error in form.errors %}
{{ error }}
{% endfor %}
Output
<!-- if the Name field was left empty by the user -->
author
You can apply the default_errors filter on form.errors
to output default error messages without having to loop through the array.
Input
{% if form.errors %}
{{ form.errors | default_errors }}
{% endif %}
Output
Please enter a valid email address.
form messages
and translated fields
You can loop through the form.messages
and form.translated_fields
arrays to get more information about the returned form.errors
object. You can target a specific array element of either array by using an error
object of form.errors
as a key.
The messages
array holds the translated error messages for values in form.errors
.
The translated_fields
array holds translated field names for values in form.errors
.
Input
<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>
Output
<ul>
<li>We have sent an email, please click the link included to verify your email address.</li>
<li>Password - Please enter a valid password.</li>
</ul>
form.first_name
Returns the first name associated with the address. Exclusive to form
tags with the "address" parameter.
form.id
Returns the id (unique identifier) of the form.
form.last_name
Returns the last name associated with the address. Exclusive to form
tags with the "address" parameter.
form.password_needed
Used only for form
tags with the "customer_login" parameter. The form.password_needed
attribute always returns true
.
form.phone
Returns the telephone number associated with the address, if it exists. Exclusive to form
tags with the "address" parameter.
form.posted_successfully?
Returns true
if the form was submitted successfully, or false
if the form contained errors. All forms but the address form set that property. The address form is always submitted successfully.
{% if form.posted_successfully? %}
Comment posted successfully!
{% else %}
{{ form.errors | default_errors }}
{% endif %}
form.province
Returns the province or state associated with the address. Exclusive to form
tags with the "address" parameter.
Input
{{ form.city }}, {{ form.province }}
Output
San Francisco, California
form.set_as_default_checkbox
Renders an HTML checkbox that can submit the current form as the customer's default address. Exclusive to form
tags with the "address" parameter.
Input
{{ form.set_as_default_checkbox }}
Output
<input type="checkbox" id="address_default_address_12345678" name="address[default]" value="1">
form.zip
Returns the zip code or postal code associated with the address. Exclusive to form
tags with the "address" parameter.