Exemple #1
0
$form->addMultipleSelect("test_mselect2", "mcountry", $countries)->value(array(1, 3))->rule("required", "Please choose a country");
$form->addMultipleSelect("test_mselect", "mcolor", array(1 => "Braun", 2 => "Red", 3 => "Blue"))->value(array(2));
$form->addRadio("test_radio", "hair", array(1 => "Braun", 2 => "Red", 3 => "Blue"))->value(3)->rule("required", "Please choose a color");
$form->addCheckboxList("test_checkboxList", "hair", array(1 => "Braun", 2 => "Red", 3 => "Blue"))->value(array(3))->rule("required", "Please choose a color");
$form->addText("test_age", "Age")->rule('min', 'minimum 5', 5)->rule('max', 'maximum 2000', 2000);
$form->addText("test_age2", "Age range")->rule('range', 'between 5 and 20', 5, 20);
$form->addTextarea("test_area", "Description")->rule('min_length', 'minimum 5 symbols', 5)->rule('max_length', 'maximum 2000 symbols', 2000);
$form->addTextarea("test_area2", "Descr. range")->rule('length', 'between 5 and 20', 5, 20);
$form->addText("fname", "First Name:")->rule('regexp', 'Името трябва да съдържа поне една голяма буква', '/[A-Z]/');
$form->addText("email", "Email:")->rule('email', 'should be valid email')->rule('callback', 'should be \'email@domain.com\'', 'callmeback');
function callmeback($val)
{
    return $val == '*****@*****.**';
}
$form->addText("url", "URL:")->rule('url', 'should be a valid url');
$form->addUpload("file", "test")->rule("required");
$form->addSubmit("submit", "Send");
$form->addSubmit("submit2", "Send2");
$tpl = new Ste();
$tpl->load('ste/form.html');
$tpl->set('form', $form->toArray());
$tpl->set('data', var_export($form->data(), true));
$tpl->set('form_code', htmlspecialchars($form));
if ($form->submitted()) {
    $data = $form->data();
    if ($data['test_area'] == '11') {
        $form->addError('test_area', 'Could not be 11');
    }
    if ($form->valid()) {
        $tpl->hide('form');
    }