本文整理汇总了PHP中HTML_QuickForm2::addRule方法的典型用法代码示例。如果您正苦于以下问题:PHP HTML_QuickForm2::addRule方法的具体用法?PHP HTML_QuickForm2::addRule怎么用?PHP HTML_QuickForm2::addRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTML_QuickForm2
的用法示例。
在下文中一共展示了HTML_QuickForm2::addRule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFormRule
public function testFormRule()
{
$form = new HTML_QuickForm2('track', 'post');
$foo = $form->addElement('text', 'foo', array('id' => 'foo'));
$form->addRule(new FormRule($form));
$this->assertFalse($form->validate());
$this->assertEquals('an error message', $foo->getError());
}
示例2: login
/**
* login checks username and password and set the loginstatus appropriate,
* returns login-form or loggedin-message
*
* @return string the html-string of login-form or message
*/
private function login()
{
// smarty-template
$sLogin = new JudoIntranetSmarty();
// decode uri
$uri = 'index.php';
$r = '';
if ($this->get('r') !== false) {
$uri = base64_decode($this->get('r'));
$r = '&r=' . $this->get('r');
}
// formular
$form = new HTML_QuickForm2('login', 'post', array('name' => 'login', 'action' => 'index.php?id=login' . $r));
// renderer
$renderer = HTML_QuickForm2_Renderer::factory('default');
$renderer->setOption('required_note', parent::lang('class.MainView#login#form#requiredNote'));
// elements
// username
$username = $form->addElement('text', 'username')->setLabel(parent::lang('class.MainView#login#form#username') . ':');
$username->addRule('required', parent::lang('class.MainView#login#rule#required.username'));
// $username->addRule('regexp','');
// password
$password = $form->addElement('password', 'password')->setLabel(parent::lang('class.MainView#login#form#password') . ':');
$password->addRule('required', parent::lang('class.MainView#login#rule#required.password'));
// $password->addRule('regexp','');
// submit-button
$form->addElement('submit', 'submit', array('value' => parent::lang('class.MainView#login#form#loginButton')));
// callback
$form->addRule('callback', 'Authentifizierung fehlgeschlagen', array('callback' => array($this, 'callback_check_login')));
// smarty-mesage
$sLogin->assign('caption', parent::lang('class.MainView#login#message#caption'));
// validate
if ($form->validate()) {
// login and redirect
$_SESSION['user']->change_user($username->getValue(), true);
header('Location:' . $uri);
exit;
} else {
// smarty message and form
$sLogin->assign('message', parent::lang($_SESSION['user']->get_login_message()));
$sLogin->assign('form', $form->render($renderer));
}
// return smarty
return $sLogin->fetch('smarty.login.tpl');
}