form smarty xtemplate pattemplate support
getVars() method
This method returns an array of form elements, which can be used in template engines (eg. like Smarty). The array format is the following:
| Array index | Description |
|---|---|
| fields | An array of HTML code
chunks, each array element is in the
'fieldname' => 'HTML chunk'
format
|
| formopen | The form opening tag including all the parameters (method, action, name, etc.). To get a working clonefish form, you have to include the value of this array element in your final HTML code. |
| script | The JavaScript code that validates the form on the client-side. To get a working clonefish form, you have to include the value of this array element in your final HTML code. |
| formclose | The form closing tag |
| messages |
An array containing error messages if
the $outputmessages property is set to 1.
|
| messageslayout | The error messages formatted according to the layout settings
(
$messageprefix,
$messagecontainerlayout,
$messagelayout,
$messagepostfix
)
|
$vars = $clonefish->getVars(); print_r( $vars );
The output:
Array(
'fields' => Array(
'name' => '<input type="text" name="name" value="James Bond">',
'id' => '<input type="text" name="id" value="007">',
'language' => '<select name="language">' .
'<option value="en">English</option>' .
'<option value="hu">Hungarian</option>' .
'<option value="fr">French</option>' .
'</select>'
),
'formopen' => '<form enctype="multipart/form-data"
name="regform" action="test.php"
onsubmit="return check_regform();" method="post">',
'script' => '[...]'
// JavaScript validation code
// including the <script></script>
// tags
'formclose' => '</form>',
// error messages, if the validation failed:
'messages' => Array(
0 => "The 'login name' field is required",
1 => "The 'password' field is required",
2 => "The 'e-mail' field is required (specify a valid e-mail address)"
// error messages formatted according to the
// message layout settings
'messageslayout' => "The following problems occured: " .
"<ul>"
"<li>The 'login name' field is required</li>" .
"<li>The 'password' field is required</li>" .
"<li>The 'e-mail' field is required (specify " .
"a valid e-mail address)</li>" .
"</ul>"
)
