Exemple #1
0
// $login->method('GET');
//$login->action('form.php')->method('post')->setAttribute('id', 'loginid')->setAttribute('class', 'left');
$login->addText('username', 'Username:'******'id', "bla");
$login->addPassword('password', 'Password:'******'submit', 'Login');
//->setAttribute('', "Vhod");//->id("loginbutton");
$reg = new Form();
// $reg->method('GET');
$reg->addText('username', "Username:"******"Please choose username");
$reg->addText("fname", "First Name:");
$reg->addText("lname", "Last Name:");
$reg->addText("email", "Your email:")->setRequired("Enter your email address");
$reg->addPassword("password", "Password:"******"Please choose password");
$reg->addPassword("password2", "Retype Password:"******"Please verify your password");
$reg->addSubmit("submit", "Register");
?>
<!doctype html>
<html>
<head>
	<style>
label.required  { color: maroon; }
input.error { background: #fdd; }
span.error {color: red;}
	</style>
</head>
<body>
<?php 
if (!$login->submitted()) {
    echo $login;
} elseif (!$login->valid()) {
Exemple #2
0
$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');
    }
}