Ejemplo n.º 1
0
 private function addDefaultValidators(Zend_Form_Element $element, $meta)
 {
     if (!$meta['NULLABLE'] && $meta['PRIMARY'] != true) {
         $element->setRequired(true);
         $element->setAllowEmpty(false);
     }
 }
Ejemplo n.º 2
0
 /**
  * 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));
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
    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);
    }
Ejemplo n.º 6
0
 /**
  * Define o elemento como obrigatório e acrescenta as classes de CSS required 
  * @param bool $flag
  * @author Jhonatan Morais <*****@*****.**>
  */
 public function setRequired($flag = true)
 {
     parent::setRequired($flag);
     if ((bool) $flag) {
         $this->addValidator("NotEmpty");
     } else {
         $this->removeValidator("NotEmpty");
     }
     return $this;
 }