Getting started


Views and routes


SQL queries

Sessions and security



Form fields settings

In this section is described how to create a form, make most common action with it and change the parameters of its fields when the form is already created.

$fields = array(array("Your name", "char", "name", array("required" => true),
                array("Gender", "enum", "gender", array("values_list" => array("male" => "Male", 
                                                                               "female" => "Female"))),
                array("Email", "email", "email"),
                array("Receive news", "bool", "news_subscribe"),
                array("Additional info", "text", "about", array("help_text" => "Tell about yourself"))

$form = new Form($fields);
//Display all fields of the form, by default using rows of table
echo $form -> display();
//Display all fields of the form, in <div> tags in vertical view
echo $form -> displayVertical();
//Display selected fields of the form in required order as table rows
echo $form -> display(array("name", "about", "email"));

//Display html code for a separate form field (without a name and wrappers)
echo $form -> displayFieldHtml("gender");

//Display a form with erros, attached to the fields
echo $form -> setDisplayWithErrors() -> display();

Add or delete a form field

$form = new Form($fields);

//Operations with fields are done before validation and displaying on the screen
$form -> addField(array("Phone number", "phone", "phone_number"));
$form -> removeField("news_subscribe");

echo $form -> display();

Change fields parameters

//Make a field mandatory to fill 
$form -> setRequired("about");

//Make several fields mandatory to fill, "*" value for all fields
$form -> setRequiredFields(array("email", "about"));

//Speciafy a field name (title)
$form -> setCaption("email", "E-mail");

//Specify explanation text for the field
$form -> setHelpText("news_subscribe", "Newsletter comes no more than 1 time/month");

//Specify additional html parameters of the field (attributes: id, class, title etc.)
$form -> setHtmlParams("about", 'id="about-me" rows="12"');

//Additional html parameters for several fields
$form -> setHtmlParams(array("email", "name"), 'class="text-input"');

Additional options

//If the values of "enum" type field is a data from other model (foreign key), then we can filter them
$form -> filterValuesList("city", array("active" => 1, "order->asc" => "name"));
//For the field of "date" type we can specify it to look as 3 select tags
$form -> setDisplaySelects("date");
//For the "enum" type field we can specify display it as radio buttons wrapper in table
//Passed value is a number of colums of table which will be radio wrapped into
$form -> setDisplayRadio("gender", 2);
//For "many_to_many" type field display values as a table with checkboxes
//(2 – a number of table columns)
$form -> setDisplayTable("interests", 2);