create a new form
$form = new Zebra_Form('my_form');
add a text control to the form
$obj = $form->add('text', 'my_text');
make the text field required
$obj->set_rule(
'required' => array(
'error', // variable to add the error message to
'Field is required' // error message if value doesn't validate
)
);
don't forget to always call this method before rendering the form
if ($form->validate()) {
for the purpose of this example, we will do a custom validation
after calling the "validate" method.
for custom validations, using the "custom" rule is recommended instead
check if value's is between 1 and 10
if ((int)$_POST['my_text']) < 1 || (int)$_POST['my_text']) > 10) {
$form->add_error('error', 'Value must be an integer between 1 and 10!');
} else {
put code here that is to be executed when the form values are ok
}
}
output the form using an automatically generated template
$form->render();