# Form

The form object is used inside the form tag.

The `form` object is used inside the [form tag](https://developer.versacommerce.de/articles/liquid-tags-theme-tags#form). 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 comments
- `body`: for message text, for example in a contact form
- `email`: for required email fields
- `password`: for required password fields
- `form`: a general error used when no more specific error applies

```liquid
{% for error in form.errors %}
    {{ error }}
{% endfor %}
```

```html
 <!-- if the Name field was left empty by the user -->
author
```

Apply the [default_errors](https://developer.versacommerce.de/articles/liquid-filters-additional-filters#defaulterrors) filter to `form.errors` to output default error messages without looping through the array.

```liquid
{% if form.errors %}
      {{ form.errors | default_errors }}
{% endif %}
```

```text
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`.

```liquid
 <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>
```

```html
<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 "customer_login" parameter. `form.password_needed` always returns `true`.

## 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.

```liquid
{% 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.

```liquid
{{ form.city }}, {{ form.province }}
```

```text
Koblenz, Rhineland-Palatinate
```

## form.set_as_default_checkbox

Outputs an HTML checkbox that submits the current form as the customer's default address. Only for `form` tags with the "address" parameter.

```liquid
{{ form.set_as_default_checkbox }}
```

```html
<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.
