@param string $template The output of the form can be generated automatically, can be given from a template
file or can be generated programmatically by a callback function.
For the automatically generated template there are two options:
- when $template is an empty string or is "*vertical", the script
will automatically generate an output where the labels are above the controls
and controls come one under another (vertical view)
- when $template is "*horizontal", the script will automatically
generate an output where the labels are positioned to the left of the controls
while the controls come one under another (horizontal view)
When templates are user-defined, $template needs to be a string representing
the path/to/the/template.php.
The template file itself must be a plain PHP file where all the controls
added to the form (except for the hidden controls, which are handled automatically)
will be available as variables with the names as described in the documentation
for each of the controls. Also, error messages will be available as described at
{@link Zebra_Form_Control::set_rule() set_rule()}.
A special variable will also be available in the template file - a variable with
the name of the form and being an associative array containing all the controls
added to the form, as objects.
The template file must not contain the tags, nor any of the
controls added to the form as these are generated automatically!
There is a third method of generating the output and that is programmatically,
through a callback function. In this case $template needs to be the name
of an existing function.
The function will be called with two arguments:
- an associative array with the form's controls' ids and their respective
generated HTML, ready for echo-ing (except for the hidden controls which will
still be handled automatically);
note that this array will also contain variables assigned through the
{@link assign()} method as well as any server-side error messages, as you
would in a custom template (see {@link Zebra_Form_Control::set_rule() set_rule()}
method and read until the second highlighted box, inclusive)
- an associative array with all the controls added to the form, as objects
THE USER FUNCTION MUST RETURN THE GENERATED OUTPUT!
public render ( string $template = '', boolean $return = false, array $variables = '' ) : mixed | ||
$template | string | |
$return | boolean | (Optional) If set to TRUE, the output will be returned instead of being printed to the screen. Default is FALSE. @param array $variables (Optional) An associative array in the form of "variable_name" => "value" representing variable names and their associated values, to be made available in custom template files. This represents a quicker alternative for assigning many variables at once instead of calling the {@link assign()} method for each variable. @return mixed Returns or displays the rendered form. |
$variables | array | |
return | mixed |