/** * See {@link PHPUnit_Framework_TestCase::setUp()} for details. */ protected function setUp() { parent::setUp(); // Usually a captcha element is rendered by the decorator, // but for testing a text field is just as well. // Using a text field avoids a dependency to the session. $element = new Zend_Form_Element_Text('my_captcha'); $element->setAttrib('id', 'my-id'); // Simulate a HtmlTag ID that is based on the element name (as configured // in the loadDefaultDecorators() mthod of the captcha element). $element->getDecorator('HtmlTag')->setOption('id', $element->getName() . '-element'); $element->setView(new Zend_View()); $this->decorator = new Mol_Form_Decorator_Captcha_Word(); $this->decorator->setElement($element); }
public function __construct($options = null) { parent::__construct($options); $this->setName('class'); $this->setIsArray(true); $classname = new Zend_Form_Element_Text(Model_ClassGenerator_FormToClass::$nameKey); $classname->setLabel('Class name')->setRequired(true)->addValidator('NotEmpty', true); $classComment = new Zend_Form_Element_Textarea(Model_ClassGenerator_FormToClass::$commentKey); $classComment->setLabel('Class comment/description'); $classComment->setAttrib('cols', '50')->setAttrib('rows', '4'); $persistenceOn = new Zend_Form_Element_Checkbox(Model_ClassGenerator_FormToClass::$withPersistenceKey); $persistenceOn->setLabel('Persistence ON'); $table = new Zend_Form_Element_Text(Model_ClassGenerator_FormToClass::$tableKey); $table->setLabel('Database Table'); $addFieldDynId = new Zend_Form_Element_Hidden('addFieldDynId'); $addFieldDynId->setAttrib('id', 'addFieldDynId'); $addFieldDynId->setValue(1); $attributesSf = self::getAttributeSubform(); $this->addSubForm($attributesSf, 'attributes', 1); /*Use table decorator! require_once('../application/forms/Decorators/Table.php'); $this->setDecorators(array( 'FormElements', array('Table', array('doNotSetDecorators' => false)), 'Form' )); */ $add = new Zend_Form_Element_Button('addAttribute'); $add->setAttrib('id', 'addAttribute'); $add->setLabel('Add Attribute'); $remove = new Zend_Form_Element_Button('removeAttribute'); $remove->setAttrib('id', 'removeAttribute'); $remove->setLabel('Remove Attribute'); $submit = new Zend_Form_Element_Submit('submit'); $submit->setLabel('Play!')->setOrder(5); $this->addElements(array($classname, $classComment, $persistenceOn, $table)); $this->addDisplayGroup(array($classname->getName(), $classComment->getName(), $persistenceOn->getName(), $table->getName()), 'Class properties')->setOrder(0); $this->addElements(array($add, $remove, $submit, $addFieldDynId)); $this->addElement('hash', 'no_csrf_foo', array('salt' => 'unique')); }
/** * @return true if string can be used as zend_form_element name, else Exception * */ private function zendConformElementName($string) { $element = new Zend_Form_Element_Text($string); $element->setName($string); if ($element->getName() !== $string) { throw new Publish_Model_FormIncorrectFieldNameException($string); } return true; }
public function init() { $this->setName(strtolower(get_class())); $this->setMethod("post"); $this->setAction("/admin/ask/chatsender"); $oFormName = new Zend_Form_Element_Hidden("form_name"); $oFormName->setValue(get_class()); $oFormName->setIgnore(FALSE)->removeDecorator("Label"); $this->addElement($oFormName); $oChatUserRecipientId = new Zend_Form_Element_Select("chat_user_recipient_id"); $oChatUserRecipientId->setLabel("Wybierz konsultanta:")->setFilters($this->_aFilters); $oChatUserRecipientId->addValidator(new Zend_Validate_InArray(array_keys($this->_aChatUserRecipients))); $oChatUserRecipientId->addValidator(new AppCms2_Validate_IsOnline()); $oChatUserRecipientId->addMultiOptions($this->_aChatUserRecipients); $oChatUserRecipientId->setRequired(TRUE); //$oChatUserRecipientId->setAttrib("class", "valid"); $this->addElement($oChatUserRecipientId); $oFirstName = new Zend_Form_Element_Text("first_name"); $oFirstName->setLabel("Imię i nazwisko:")->setFilters($this->_aFilters); $oFirstName->addValidator(new Zend_Validate_Alpha(array("allowWhiteSpace" => true))); $oFirstName->setRequired(TRUE)->setValue(trim($this->_aUser["first_name"] . " " . $this->_aUser["last_name"])); //$oFirstName->setAttrib("class", "valid"); $this->addElement($oFirstName); $oEmailAddress = new Zend_Form_Element_Text("email_address"); $oEmailAddress->setLabel("Adres e-mail:")->setFilters($this->_aFilters); $oEmailAddress->addValidator(new Zend_Validate_EmailAddress()); $oEmailAddress->setRequired(TRUE)->setValue($this->_aUser[$oEmailAddress->getName()]); //$oEmailAddress->setAttrib("class", "valid"); $this->addElement($oEmailAddress); $oUserCategoryId = new Zend_Form_Element_Select("user_category_id"); $oUserCategoryId->setLabel("Kategoria użytkownika:")->setFilters($this->_aFilters); $oUserCategoryId->addMultiOptions($this->_aCategory); $oUserCategoryId->setRequired(TRUE)->setValue($this->_aUser[$oUserCategoryId->getName()]); $oUserCategoryId->setAttrib("class", "valid"); //$this->addElement($oUserCategoryId); $oPhone = new Zend_Form_Element_Text("phone"); $oPhone->setLabel("Numer telefonu:")->setFilters($this->_aFilters); $oPhone->addValidator(new AppCms2_Validate_CellPhone()); $oPhone->setRequired(FALSE)->setValue($this->_aUser["phone_number"]); $oPhone->setAttrib("class", "valid"); //$this->addElement($oPhone); $oBBarcode = new Zend_Form_Element_Text("bbarcode_id"); $oBBarcode->setLabel("Numer karty bibliotecznej:")->setFilters($this->_aFilters); $oBBarcode->addValidator(new AppCms2_Validate_BBarcode()); $oBBarcode->addValidator(new Zend_Validate_Digits()); $oBBarcode->setRequired(FALSE)->setValue($this->_aUser[$oBBarcode->getName()]); $oBBarcode->setAttrib("class", "valid"); //$this->addElement($oBBarcode); //$this->addDisplayGroup(array($oPhone, $oBBarcode), "not_valid", array("legend" => "Wprowadzenie poniższych danych nie jest obowiązkowe, ale ułatwi udzielenie odpowiedzi lub skontaktowanie się z Państwem telefonicznie")); $this->addElement("hash", "csrf_token", array("ignore" => false, "timeout" => 7200)); $this->getElement("csrf_token")->removeDecorator("Label"); $oSubmit = $this->createElement("submit", "submit"); $oSubmit->setLabel("Dalej"); $this->addElement($oSubmit); $oViewScript = new Zend_Form_Decorator_ViewScript(); $oViewScript->setViewModule("admin"); $oViewScript->setViewScript("_forms/_defaultform.phtml"); $this->clearDecorators(); $this->setDecorators(array(array($oViewScript))); $oElements = $this->getElements(); foreach ($oElements as $oElement) { $oElement->setFilters($this->_aFilters); $oElement->removeDecorator("Errors"); } }