コード例 #1
0
 public function testBind()
 {
     $form = new phForm('test', 'simpleTestView');
     $form->bindAndValidate(array('username' => 'test', 'password' => 'pass'));
     $this->assertTrue($form->isValid(), 'form is correctly valid');
     /*
      * change the value of username directly and check
      * that getValue on the form returns the values of
      * its data items and not what was bound to it
      */
     $form->username->bind('new');
     $this->assertEquals(array('username' => 'new', 'password' => 'pass'), $form->getValue(), 'getValue returns correct data');
 }
コード例 #2
0
 * The second argument is the form template to use.
 */
$form = new phForm('register', 'registerForm');
/*
 * set the various validators
 */
$form->fullname->setValidator(new phRequiredValidator());
// note that fullname is the value of the name helper in the form and NOT the id helper
$form->email->setValidator(new phRequiredValidator());
$form->password->setValidator(new phRequiredValidator());
$form->confirmPassword->setValidator(new phCompareValidator($form->password, phCompareValidator::EQUAL));
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    /*
     * data has been posted back, bind it to the form
     */
    $form->bindAndValidate($_POST['register']);
    if ($form->isValid()) {
        /*
         * form data is valid, put your code to
         * register a new user here
         */
        echo "<h1>Registration Complete!</h1>";
    }
}
?>
<form action="/registration/register.php" method="post">
	<?php 
echo $form;
// this will render the form
?>
</form>