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 |
---|---|
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 |
attr
string |
Allows you to set any number of HTML attributes on the |
Variables
fields
array |
An array of the fields in your formset. Each field contains an |
---|---|
errors
array |
An indexed array of any validation errors upon submission. Suitable for looping through. eg. |
error
array |
An array of validation errors indexed by field names. Suitable for targeting fields. eg. |
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 |