Form tags

Table of contents

Below you find all the tags relating forms:

form_input_name

Returns a string that can be used as name for HTML input tags inside the form Liquid tag. This filter must be used to ensure that an input field is processed correctly by Plate. The input for this filter is the name that represents the field, for example “Name” or “Email”. Read more about html_input to change te input type

{{ "Name" | form_input_name }}
Input
form_message[content][name]
Output

register_form_field

Registers a form field by name, in Plate. This ensures that when a form is submitted Plate expects this form, and possibly validates the field. The tag can only be used within a form block. It accepts the name of the field as an input (for example “Name” or “Email”), but also whether this field should be validated (with the required argument).

Accepts the following arguments (excluding the first argument, which is the name):

  • required: whether the registered field should be validated on presence. (Default: false)

  • array: whether the input sent for the registered field is an array. E.g. with multiple file fields (Default: false)


{% register_form_field field_line.name, required: field_line.required, array: false %}
Example

Note that this tag does not directly output anything in the HTML. In the background this tag adds some information to a hash that is generated by the form tag.

To generate the HTML, use the form_input_name and html_input filters.

{{ "Name" | form_input_name | html_input: "checkbox" }}
Input
<input type="checkbox" name="form_message[content][name]">
Output

register_form_confirmation_field

Registers a form field to be a confirmation_field. A confirmation_field is a field which value will be an email address to which a confirmation mail should be sent after the form is submitted. This will allow you to build forms which send a confirmation mail to the person who filled in the form, and to overwrite the template which is send to the fixed email address which is given as parameter for the form tag.

You can also use the register_form_confirmation_field tag to send a custom mail to an Admin. In this case, you specify the email address to which a confirmation mail is sent directly with the 'to' argument. This argument is used instead of a confirmation_field in which the email will be provided by the site visitor.

You have to give the content for the confirmation email. You can give this by either directly inputting the content into the tag (using the "body" argument), or by specifying a template (theme file). You should put the template in the "mails" folder in the root of your theme.

Accepts the following arguments (excluding the first argument, which is the name of the form field):

  • body: the content for the confirmation email.
  • template: the template for the confirmation email.
  • subject: the subject for the confirmation email. (Not required, default: 'Confirmation of filling out contact form via %{site}')

Note: Only 1 of the arguments body and template is allowed at the same time.

Note: This tag does not replace the tag 'register_form_field', so to activate a field in the form, you still have to use the 'register_form_field' tag.

Note: This tag has a gracious error handling, meaning that if a field that is registered as confirmation_field is not given, or does not contain a valid email address, the confirmation mail will not be sent.

User Custom confirmation email

Example 1:

{% register_form_confirmation_field "person_email", body: "Thanks for your info!" %}

This will register the field "person_email" as a confirmation_field. When someone fills in the form, and inputs someone@getplate.com in the field person_email, then an email will be sent to someone@getplate.com with the content: "Thanks for your info".

Example 2:
{% register_form_confirmation_field "person_email", template: "default_email" %}

This will register the field "person_email" as a confirmation_field. When someone fills in the form, and inputs someone@getplate.com in the field person_email, then an email will be sent to someone@getplate.com with the content found in the theme file located at "/mails/default_email.plate".

Admin custom confirmation email

{% register_form_confirmation_field subject: "This is the email subject",
body: "This is the email body", to: "example@email.com" %}
Example 1

This will register the argument given for ‘to’ as the email address to which the confirmation mail will be sent. This contains “This is the email subject” as subject and “This is the email body" as the email body.

{% assign subject = "Confirmation subject {{ submitted_form_fields['name'] }}"  %}
{% register_form_confirmation_field 
  subject: subject,
  body: "This is the email body", 
  to: "example@email.com" 
%}
Example 2

The following Objects are accessible inside the mail templates:

  • submitted_form_fields similar to the object in that is accessible in the form tag. This allows you to render the submitted fields in the confirmation email.

  • site The same as the site objects inside the Plate templating language

  • form The element that represents the form, so the object used in the for attribute of the form tag.

An example template could look like this (assuming one of the fields is named "Name"):

Dear {{ submitted_form_fields["Name"] }}
<br> 
Thank you very much for your message on {{ site.name }}. We will get back to you within the hour.
<br>
<br>
Kind regards
<br>
The Plate-Team

Need help?

Do you have any question which is not answered in this knowledge base? Contact us. We are here to help you.