Create

Generate necessary <form> markup to accept form submissions.


Example

Here we’ll be creating a form to submit an entry in the contact form.

{{ form:create in="contact" }}

    {{ if errors }}
        <div class="alert alert-danger">
            {{ errors }}
                {{ value }}<br>
            {{ /errors }}
        </div>
    {{ /if }}

    {{ if success }}
        <div class="alert alert-success">
            Form was submitted successfully.
        </div>
    {{ /if }}

    {{# You can loop through fields from the formset... #}}
    {{ fields }}
        <div class="form-group">
            <label>{{ display }}</label>
            <input type="text" name="{{ name }}" value="{{ old }}" />
        </div>
    {{ /fields }}

    {{# Or you can hardcode fields... #}}
    <div class="form-group">
        <label>Email</label>
        <input type="text" name="email" value="{{ old:email }}" />
    </div>

    <button>Submit</button>

{{ /form:create }}

Parameters

formset|in

string

The name of the formset this form should use. This is only required if you do not use the form:set tag, or if you don't have a formset defined in the current context.

redirect

string

The location your user will be taken after a successful form submission. If left blank, the user will stay on the same page.

error_redirect

string

The same as redirect, but for failed submissions.

attr

string

Allows you to set any number of HTML attributes on the <form> tag. You can specify multiple attributes by pipe delimiting them. eg. attr="class:pretty-form|id:contact"


Variables

fields

array

An array of the fields in your formset. Each field contains an old value that holds previous input in the case of failed submission.

errors

array

An indexed array of any validation errors upon submission. Suitable for looping through. eg. {{ errors }}{{ value }}{{ /errors }}

error

array

An array of validation errors indexed by field names. Suitable for targeting fields. eg. {{ error:email }}

old

array

An array of submitted values from the previous request. Useful for re-populating fields if there are validation errors.

success

boolean

This will be true if the form was submitted successfully.

Last modified on December 6, 2016