form

The form object is used within the form tag. It contains attributes of its parent form.

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.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 of the form were left empty or contained errors. Possible values are:

  • author
  • body
  • email
  • form
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.

If you want more control over the markup of the errors, you can loop through the messages and translated_fields arrays that are part of the form.errors object.

<ul>
    {% for field in form.errors %}
      {% if field == 'form' %}
        <li>
              {{ form.errors.messages[field] }}
      </li>
      {% else %}
      <li>
          {{ form.errors.translated_fields[field] }} - {{ form.errors.messages[field] }}
        </li>
    {% endif %}
    {% endfor %}
</ul>

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 %}

results matching ""

    No results matching ""