Yoolk Liquid

Home Objects Form

Form

The form object can only be used within form tag. It has the following attributes:

form.posted_successfully?

Returns true if a comment by the user was submitted successfully, or false if the form contained errors

{% if form.posted_successfully? %}
  <div class="successForm contact">
    <p>Thanks for contacting us! We'll get back to you as soon as possible.</p>
  </div>
{% endif %}

form.errors

Returns an array of error fields if the form was not submitted successfully. As shown below, the example loops through the error and print out the message on each field at the top of the form.

Input

<ul>
  {% for field in form.errors %}
    <li>
      <span>{{ field }}</span>
      <span>{{ form.errors.messages[field] }}</span>
    </li>
  {% endfor %}
</ul>

Output

Oops, sorry. We were unable to submit your inquiry because it contained 2 errors. Please correct the following and submit again:

- sender You can't leave this empty
- body You can't leave this empty