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 “Naam” 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
)
Example:
{% register_form_field field_line.name, required: field_line.required, array: false %}
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.
Input:
{{ "Name" | form_input_name | html_input: "checkbox" }}
Output:
<input type="checkbox" name="form_message[content][name]">
With JSON endpoint
It is possible to send the request for a form to a JSON endpoint. You can read more about this in the docs for form tag. When sending in the content for each field, every field just handles like "key": "value"
in the form JSON. However, content for file fields need to be decoded as base64, and accept a JSON object as content:
The filename
key is optional. When it is not given the filename is generated randomly and the extension extracted from the base64 string, if possible.