public function testValidationFailure() { $validator = new Frontdoor_Form_AtLeastOneValidator(); $checkbox1 = new Zend_Form_Element_Checkbox('checkbox1'); $checkbox2 = new Zend_Form_Element_Checkbox('checkbox2'); $validator->addField($checkbox1); $validator->addField($checkbox2); $this->assertFalse($validator->isValid(null, array('checkbox1' => '0', 'checkbox2' => '0'))); }
/** * Build mail form * * @return void */ public function init() { $atLeastOne = new Frontdoor_Form_AtLeastOneValidator(); $authorSub = new Zend_Form_SubForm('a'); if (!is_null($this->_authors)) { $authCheck = null; foreach ($this->_authors as $author) { $options = array('checked' => true); if (count($this->_authors) == 1) { $options['disabled'] = true; } $authCheck = new Zend_Form_Element_Checkbox($author['id'], $options); $atLeastOne->addField($authCheck); $authCheck->setLabel($author['name']); $authorSub->addElement($authCheck); if (count($this->_authors) == 1) { $authCheck->setUncheckedValue(1); } } $authCheck->addValidator($atLeastOne); $this->addSubForm($authorSub, 'authors'); } $sender = new Zend_Form_Element_Text('sender'); $sender->setRequired(true); $sender->setLabel('frontdoor_sendername'); $sender_mail = new Zend_Form_Element_Text('sender_mail'); $sender_mail->setRequired(true); $sender_mail->setLabel('frontdoor_sendermail'); $sender_mail->addValidator('EmailAddress'); $message = new Zend_Form_Element_Textarea('message'); $message->setRequired(true); $message->setLabel('frontdoor_messagetext'); $captcha = new Zend_Form_Element_Captcha('foo', array('label' => 'label_captcha', 'captcha' => array('captcha' => 'Figlet', 'wordLen' => 6, 'timeout' => 300))); $submit = new Zend_Form_Element_Submit('frontdoor_send_mailtoauthor'); $submit->setLabel('frontdoor_send_mailtoauthor'); $this->addElements(array($sender, $sender_mail, $message, $captcha, $submit)); }