Forms
Forms, created in the control panel, are essentially a group of custom fields that, when submitted, are saved in the database (viewable in the control panel) and potentially emailed to a specified email address. Each form is mapped to a custom URL.
Templates
Each form can be mapped to any template in your theme folder but, by default, forms are displayed with the form.thtml template.
Example Form Template
{extends file="layout.thtml"}
{block name="title"}
{$title} - {$smarty.block.parent}
{/block}
{block name="content"}
<h1>{$title}</h1>
{if $text}{$text}{/if}
<form class="form validate" enctype="multipart/form-data" method="post" action="{url path="forms/form/submit"}">
<input type="hidden" name="form_id" value="{$id}" />
{if $validation_errors}
<div class="errors">
{$validation_errors}
</div>
{/if}
<ul class="form">
{foreach $custom_fields as $field}
{if $field.type != 'checkbox'}
<li>
<label class="full" for="{$field.name}">{$field.friendly_name}</label>
</li>
<li>
{custom_field field=$field value=$values[$field.name]}
</li>
{else}
<li>
{custom_field field=$field value=$values[$field.name]} <label for="{$field.name}" >{$field.friendly_name}</label>
</li>
{/if}
{if $field.help}
<li>
<div class="help flush">{$field.help}</div>
</li>
{/if}
{/foreach}
</ul>
<input type="submit" class="button" name="go" value="{$button_text}" />
</form>
{/block}
Form Template Variables
| Variables | ||
| Variable | Description | |
| {$id} | The form's ID. | |
| {$link_id} | The corresponding link ID in the universal links database. | |
| {$title} | The form's title | |
| {$text} | The form's introductory text. | |
| {$custom_fields} | An array of all of the custom fields building this form. See for details on displaying the custom fields. | |
| {$table_name} | The database table used to store form responses. | |
| {$admin_link} | The link in the administrator control panel for form responses. | |
| {$url} | The absolute URL to the form. | |
| {$url_path} | The relative path to the form. | |
| {$email} | The email address used for form responses. | |
| {$button_text} | The text for the form's submit button. | |
| {$redirect} | The relative path for the redirection after form submission. | |
| {$privileges} | If the form is restricted for viewing by certain member groups, this variable is an array of those member group ID's. | |
| {$num_responses} | How many responses to the form have been submitted? | |
| {$template} | The template file used to display the form. | |
Template Plugins
{form}
Retrieve a form and display it in any template. Returns all variables specified above into the $var-named array.
| Parameters | ||
| Variable | Required? | Description |
| var | Required | Specify the name for the returned variable array (e.g., "form" returns an array with keys like {$form.title}. |
| id | Required | The form ID for a specific piece of content to retrieve. |
{form var="form" id="X"}
<form class="form validate" enctype="multipart/form-data" method="post" action="{url path="forms/form/submit"}">
<input type="hidden" name="form_id" value="{$form.id}" />
{if $form.validation_errors}
<div class="errors">
{$form.validation_errors}
</div>
{/if}
<ul class="form">
{foreach $form.custom_fields as $field}
{if $field.type != 'checkbox'}
<li>
<label class="full" for="{$field.name}">{$field.friendly_name}</label>
</li>
<li>
{custom_field field=$field value=$values[$field.name]}
</li>
{else}
<li>
{custom_field field=$field value=$values[$field.name]} <label for="{$field.name}" >{$field.friendly_name}</label>
</li>
{/if}
{if $field.help}
<li>
<div class="help flush">{$field.help}</div>
</li>
{/if}
{/foreach}
</ul>
<input type="submit" class="button" name="go" value="{$form.button_text}" />
</form>
{/form}