本文整理汇总了PHP中Zend_Form_Element::setRequired方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form_Element::setRequired方法的具体用法?PHP Zend_Form_Element::setRequired怎么用?PHP Zend_Form_Element::setRequired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form_Element
的用法示例。
在下文中一共展示了Zend_Form_Element::setRequired方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addDefaultValidators
private function addDefaultValidators(Zend_Form_Element $element, $meta)
{
if (!$meta['NULLABLE'] && $meta['PRIMARY'] != true) {
$element->setRequired(true);
$element->setAllowEmpty(false);
}
}
示例2:
/**
* Creates the registration form and it's elements.
* Also sets the validation techniques for the fields
*/
function __construct()
{
parent::__construct();
$this->setName('Registration');
$this->setMethod('POST');
$this->setAction('/user/register');
$username = new Zend_Form_Element('username');
$username->setLabel('Username');
$username->setRequired(true);
$username->addValidator('NotEmpty', true);
$username->addValidator(new Zend_Validate_StringLength(6, 10), true);
$username->addValidator('Alnum', true);
$username->addValidator(new User_Models_Forms_Validators_IsUnique('username'));
$password = new Zend_Form_Element_Password('password');
$password->setLabel('Password');
$password->setRequired(true);
$password->addValidator('NotEmpty', true);
$password->addValidator(new Zend_Validate_StringLength(6, 10));
$gender = new Zend_Form_Element_Select('gender');
$gender->setLabel('Gender');
$gender->setMultiOptions(array('Male' => 'Male', 'Female' => 'Female'));
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email');
$email->setRequired(true);
$email->addValidator('NotEmpty', true);
$email->addValidator(new User_Models_Forms_Validators_EmailAddress(), true);
$email->addValidator(new User_Models_Forms_Validators_IsUnique('email'));
$paymentEmail = new Zend_Form_Element_Text('paymentEmail');
$paymentEmail->setLabel('Payment Email');
$paymentEmail->setRequired(true);
$paymentEmail->addValidator('NotEmpty', true);
$paymentEmail->addValidator(new User_Models_Forms_Validators_EmailAddress(), true);
$paymentEmail->addValidator(new User_Models_Forms_Validators_IsUnique('paymentEmail'));
$countries = new Zend_Form_Element_Select('country');
$countries->setMultiOptions(self::getCountries());
$countries->setLabel('Country');
$countries->addValidator('NotEmpty');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Register');
$this->addElements(array($username, $password, $gender, $email, $paymentEmail, $countries, $submit));
}
示例3:
function __construct()
{
parent::__construct();
$this->setName('Registration');
$this->setMethod('POST');
$this->setAction('/user/login');
$username = new Zend_Form_Element('username');
$username->setLabel('Username');
$username->setRequired(true);
$username->addValidator('NotEmpty', true);
$username->addValidator(new Zend_Validate_StringLength(6, 10));
$username->addValidator('Alnum', true);
$password = new Zend_Form_Element_Password('password');
$password->setLabel('Password');
$password->setRequired(true);
$password->addValidator('NotEmpty', true);
$password->addValidator(new Zend_Validate_StringLength(6, 10));
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Register');
$this->addElements(array($username, $password, $submit));
}
示例4: testRenderAppendsRequiredClassToClassProvidedInRequiredElement
public function testRenderAppendsRequiredClassToClassProvidedInRequiredElement()
{
$element = new Zend_Form_Element('foo');
$element->setRequired(true)->setView($this->getView())->setLabel('My Label')->setAttrib('class', 'bazbat');
$this->decorator->setElement($element);
$content = 'test content';
$test = $this->decorator->render($content);
$this->assertRegexp('/<label[^>]*?class="[^"]*required/', $test, $test);
$this->assertNotRegexp('/<label[^>]*?class="[^"]*bazbat/', $test, $test);
}
示例5: testRenderAddsRequiredClassForNonRequiredElements
public function testRenderAddsRequiredClassForNonRequiredElements()
{
$element = new Zend_Form_Element('foo');
$element->setRequired(true)
->setView($this->getView())
->setLabel('My Label');
$this->decorator->setElement($element);
$content = 'test content';
$test = $this->decorator->render($content);
$this->assertRegexp('/<label[^>]*?class="[^"]*required/', $test, $test);
$element->class = "bar";
$this->decorator->setOption('class', 'foo');
$test = $this->decorator->render($content);
$this->assertNotContains('bar', $test);
$this->assertRegexp('/<label[^>]*?class="[^"]*foo/', $test, $test);
$this->assertRegexp('/<label[^>]*?class="[^"]*required/', $test, $test);
}
示例6: setRequired
/**
* Define o elemento como obrigatório e acrescenta as classes de CSS required
* @param bool $flag
* @author Jhonatan Morais <jhonatanvinicius@gmail.com>
*/
public function setRequired($flag = true)
{
parent::setRequired($flag);
if ((bool) $flag) {
$this->addValidator("NotEmpty");
} else {
$this->removeValidator("NotEmpty");
}
return $this;
}