form smarty xtemplate pattemplate support
getVars()
clonefish->getVars() - get the form as HTML/JS snippets in an array
Description
class clonefish { array getVars( void ) }
This method returns an array of strings to be used with template engines like Smarty.
Return values
The returned array format is the following:
fields
An associative array of HTML code snippets, something like:
Array(
'login' => '<input type="text" name="login" />',
'password' => '<input type="password" name="password" />',
)
formopen
The form opening tag including all the parameters (method, action, name, etc.). To get a working clonefish form, you must include this string in your final HTML code.
script
The JavaScript code that validates the form on the client-side. To get a working clonefish form with client side validation, you must include this string in your final HTML code.
formclose
The form closing tag.
messages
An array containing error messages.
messageslayout
The error messages rendered in HTML based on the message layout settings if $clonefish->outputmessages
is set to 1. Returns an empty string if $clonefish->outputmessages
is set to 0.
Examples
<?php
$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>" )
form validation for developers!
clonefish is a proven, mature form generator class that helps PHP developers to create, validate and process secure, flexible and easy-to-maintain formslearn more