Ejemplo n.º 1
0
 public function testIdAndMethodAreReadonly()
 {
     $form = new HTML_QuickForm2('foo', 'get');
     try {
         $form->removeAttribute('id');
     } catch (HTML_QuickForm2_InvalidArgumentException $e) {
         try {
             $form->setAttribute('method', 'post');
         } catch (HTML_QuickForm2_InvalidArgumentException $e) {
             try {
                 $form->setId('newId');
             } catch (HTML_QuickForm2_InvalidArgumentException $e) {
                 return;
             }
         }
     }
     $this->fail('Expected HTML_QuickForm2_InvalidArgumentException was not thrown');
 }
Ejemplo n.º 2
0
        output_element($element);
    }
    echo "</fieldset>\n";
}
// in real application the password check will a bit be different, of course
function check_password($password)
{
    return $password == 'qwerty';
}
//
// Form setup
//
require_once 'HTML/QuickForm2.php';
$form = new HTML_QuickForm2('basicRules');
// for file upload to work
$form->setAttribute('enctype', 'multipart/form-data');
// data source with default values:
$form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('testUsername' => 'luser')));
// override whatever value was submitted
$form->addElement('hidden', 'MAX_FILE_SIZE')->setValue('102400');
//
// Simple fields validation, rule chaining
//
$fsAuth = $form->addElement('fieldset')->setLabel('Auth credentials');
$username = $fsAuth->addElement('text', 'testUsername', array('style' => 'width: 200px;'))->setLabel('Username (letters only):');
$fsPasswords = $fsAuth->addElement('fieldset')->setLabel('Supply password only if you want to change it');
$oldPassword = $fsPasswords->addElement('password', 'oldPassword', array('style' => 'width: 200px;'))->setLabel('Old password (<i>qwerty</i>):');
$newPassword = $fsPasswords->addElement('password', 'newPassword', array('style' => 'width: 200px;'))->setLabel('New password (min 6 chars):');
$repPassword = $fsPasswords->addElement('password', 'newPasswordRepeat', array('style' => 'width: 200px;'))->setLabel('Repeat new password:'******'required', 'Username is required');
$username->addRule('regex', 'Username should contain only letters', '/^[a-zA-Z]+$/');