Files
liquid/_posts/objects/form.md
2014-07-23 11:17:11 -04:00

2.4 KiB

layout, title, nav
layout title nav
default form
group
Liquid Variables

form

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

{% table_of_contents %}

{% anchor_link "form.author", "form-author" %}

Returns the name of the author of the blog article comment. Exclusive to form tags with the "article" parameter.

{% anchor_link "form.body", "form-body" %}

Returns the content of the blog article comment. Exclusive to form tags with the "article" parameter.

{% anchor_link "form.email", "form-email" %}

Returns the email of the blog article comment's author. Exclusive to form tags with the "article" parameter.

{% table_of_contents %}

{% anchor_link "form.errors", "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

{% highlight html %}{% raw %} {% for error in form.errors %} {{ error }} {% endfor %} {% endraw %}{% endhighlight %}

Output

{% highlight html %}{% raw %} author {% endraw %}{% endhighlight %}

You can apply the default_errors filter on form.errors to output default error messages without having to loop through the array.

Input

{% highlight html %}{% raw %} {% if form.errors %} {{ form.errors | default_errors }} {% endif %} {% endraw %}{% endhighlight %}

Output

{% highlight html %}{% raw %} Please enter a valid email address. {% endraw %}{% endhighlight %}

{% anchor_link "form.posted_successfully?", "form-posted_successfully" %}

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

{% highlight html %}{% raw %} {% if form.posted_successfully? %} Comment posted successfully! {% else %} {{ form.errors | default_errors }} {% endif %} {% endraw %}{% endhighlight %}