Ejemplo n.º 1
0
// and old password shuld be given
$newPassword->addRule('empty')->and_($repPassword->addRule('empty'))->or_($newPassword->createRule('eq', 'The passwords do not match', $repPassword))->and_($newPassword->createRule('minlength', 'The password is too short', 6))->and_($oldPassword->createRule('nonempty', 'Supply old password if you want to change it'));
//
// File uploads validation
//
$fsUpload = $form->addElement('fieldset')->setLabel('Upload picture (try one > 100 kB for fun)');
$upload = $fsUpload->addElement('file', 'testUpload', array('style' => 'width: 200px'))->setLabel('Picture (gif, jpg, png, <=20kB):');
// no longer using special 'uploadedfile' rule for uploads
$upload->addRule('required', 'Please upload picture');
// no longer using 'filename' rule for uploads
$upload->addRule('regex', 'Allowed extensions: .gif, .jp(e)g, .png', '/\\.(gif|jpe?g|png)$/i');
$upload->addRule('mimetype', 'Your browser doesn\'t think that\'s an image', array('image/gif', 'image/png', 'image/jpeg', 'image/pjpeg'));
$upload->addRule('maxfilesize', 'File is too big, allowed size 20kB', 20480);
$form->addElement('submit', 'testSubmit', array('value' => 'Send'));
if ($form->validate()) {
    echo "<pre>\n";
    var_dump($form->getValue());
    echo "</pre>\n<hr />";
    $form->toggleFrozen(true);
}
echo '<form' . $form->getAttributes(true) . ">\n";
foreach ($form as $element) {
    output_element($element);
}
?>

</form>

  </body>

</html>