isValid() публичный Метод

Determine whether or not the form object is valid and return the result.
public isValid ( ) : boolean
Результат boolean
Пример #1
0
<?php

require_once '../../bootstrap.php';
use Pop\Form\Form;
use Pop\Validator;
try {
    $fields = array('username' => array('type' => 'text', 'label' => 'Username:'******'required' => true, 'attributes' => array('size' => 40), 'validators' => new Validator\AlphaNumeric()), 'password' => array('type' => 'password', 'label' => 'Password:'******'required' => true, 'attributes' => array('size' => 40)), 'my_captcha' => array('type' => 'captcha', 'label' => 'Please Solve: ', 'attributes' => array('size' => 10), 'expire' => 120), 'submit' => array('type' => 'submit', 'value' => 'SUBMIT'));
    $form = new Form($_SERVER['PHP_SELF'], 'post', $fields, '    ');
    if ($_POST) {
        $form->setFieldValues($_POST, array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8')));
        if (!$form->isValid()) {
            $form->render();
        } else {
            // Option to clear out and reset security token
            $form->clear();
            echo 'Form is valid.<br />' . PHP_EOL;
            print_r($form->getFields());
        }
    } else {
        $form->render();
    }
    echo PHP_EOL . PHP_EOL;
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
Пример #2
0
 public function testAddElements()
 {
     $e = new Element('text', 'username', 'Username');
     $c = new Checkbox('colors', array('Red', 'Green', 'Blue'));
     $r = new Radio('colors', array('Red', 'Green', 'Blue'));
     $s = new Select('colors', array('Red', 'Green', 'Blue'));
     $t = new Textarea('comments');
     $f = new Form('/submit', 'post');
     $f->addElements($e);
     $f->addElements(array($c, $r, $s, $t));
     $this->assertEquals(5, count($f->getElements()));
     $this->assertInstanceOf('Pop\\Form\\Element', $f->getElement('username'));
     $this->assertTrue($f->isValid());
     $this->assertEquals(0, count($f->getErrors()));
 }