Form Fields Settings

Create a form and change the parameters of it’s fields.

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

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

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

Add/delete a field

$form = new Form($fields);

//Operations with fields are done before validation and display fields 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
$form -> setCaption("email", "E-mail");

//Specify explanatory 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" class="text-field" rows="12"');

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

Additional options

//If the value of "enum" type field are data of 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 displaying an image as 3 select tags
$form -> setDisplaySelects("date");
//For the "enum" type field we can specify display it as a radio button
$form -> setDisplayRadio("gender", 2);
//For "many_to_many" type field display values as a table with checkboxes
//(2 – a number of table columns, can be changed)
$form -> setDisplayTable("interests", 2);