Exemple #1
0
    }
})->validator(function ($value) {
    //second validator
    if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
        return "This is not a valid email address";
    }
});
/* password + confirmation */
$form->addPasswordField('password')->label('Password')->validator(function ($value) {
    if (strlen($value) < 5) {
        return 'Password cannot be less than 5 characters';
    }
});
$form->addPasswordField('confirm_password')->label('Confirm Password')->validator(function ($value) use($form) {
    //example of using another field's value in a field validator via the USE keyword
    if ($value != $form->getField('password')->getSubmittedValue()) {
        return 'Password Confirmation did not match password';
    }
});
/* submit */
$form->addButton('submit')->label('Submit')->action(function ($form) {
    if ($form->isValid()) {
        if (rand(1, 10) <= 5) {
            $form->addError('We have decided to randomly reject your registration. Sorry!');
            return false;
        } else {
            return true;
        }
    }
});
$form->addButton('login')->label('or Login')->action(function ($form) {