Section: display only form values
« Using a form after a submit | ^ jForms: automatic forms | Security in forms » |
− Table of content
With jForms, you can also display not the form but only its data. It can be useful as a reporting of input steps for example.
Automatic or default display ¶
For you in hurry, this template plugin will fully display your form data.
its name: formdatafull
. With it, you won't control how each controls labels and
values are displayed. Just pass it your form object.
Here is an example, in a controller :
$form = jForms::get('myform');
$tpl = new jTpl();
$tpl->assign('form', $form);
Et dans le template :
<h1>Your form</h1>
<p>Your inputs:</p>
{formdatafull $form}
Form labels and values are displayed in a table.
Customized display ¶
As for form display, you can control how your form data are displayed and precisely in which markup labels and values are wrapped.
Use {formcontrols}
and {ctrl_label}
plugins similarly to form display
and also {ctrl_value}
instead of {ctrl_control}
:
<h1>Your form</h1>
<p>Your inputs:</p>
<table>
{formcontrols $form}
<tr>
<th scope="row">{ctrl_label}</th>
<td>{ctrl_value}</td>
</tr>
{/formcontrols}
</table>
Note: {form}
is not needed here as opposed to complete form display.
You are also free to not use {formcontrols}
loops, and display only your labels and values
of choice, in which ever order. To achieve this, use {ctrl_label}
and {ctrl_value}
and call them with your selected control names. But they must be used inside a {formdata}
plugin:
<h1>Your form</h1>
<p>Your inputs:</p>
<table>
{formdata $form}
<tr>
<th>{ctrl_label 'name'}</th>
<td>{ctrl_value 'name'}</td>
</tr>
<tr>
<th>{ctrl_label 'address'}</th>
<td>{ctrl_value 'address'}</td>
</tr>
{/formdata}
</table>
{ctrl_value}
accepts an additionnal parameter which should be a string to format
the value. The formatting is done by sprintf()
.