zend-form

zend form validation

血红的双手。 提交于 2019-12-05 15:44:47
I wonder how Zend_Form validates inputs, I mean how does it know which input fields to validate. I looked to php globals($_POST, $_GET) and I didn't see anything set as an identifier(for example ) in order to know how validate. Can anyone suggest me any guide for this stuff? Well, the best option to find out is to look at the code of Zend_Form : /** * Validate the form * * @param array $data * @return boolean */ public function isValid($data) { if (!is_array($data)) { require_once 'Zend/Form/Exception.php'; throw new Zend_Form_Exception(__METHOD__ . ' expects an array'); } $translator = $this-

Zend Form Element with Javascript - Decorator, View Helper or View Script?

一个人想着一个人 提交于 2019-12-05 15:30:45
I want to add some javacsript to a Zend_Form_Element_Text . At first I thought a decorator would be the best way to do it, but since it is just a script (the markup doesn't change) then maybe a view helper is better? or a view script? It seems like they are all for the same purpose (regarding a form element). The javascript I want to add is not an event (e.g. change, click, etc.). I can add it easily with headScript() but I want to make it re-usable , that's why I thought about a decorator/view helper. I'm just not clear about the difference between them. What is the best practice in this case

How to set the message of the NotEmpty validator on a Zend_Form_Element?

与世无争的帅哥 提交于 2019-12-05 12:44:46
I have a form element that I'm setting as required: $this->addElement('text', 'email', array( 'label' => 'Email address:', 'required' => true )); Since I'm setting required to true, it makes sure that it's not empty. The default error message looks like this: "Value is required and can't be empty" I tried setting the message on the validator, but this throws a fatal error: $validator = $this->getElement('email')->getValidator('NotEmpty'); $validator->setMessage('Please enter your email address.'); Call to a member function setMessage() on a non-object How can I set the message to a custom

Subscript or Superscript text within a Zend Form label

我是研究僧i 提交于 2019-12-05 12:35:59
I would like to include subscript text in a Zend_Form_Element's label, and it doesn't seem to be working: $zend_form_element->setLabel('Label <sub>x</sub>'); Is there anything I can do to get it to output properly without having to manually write the form on the view page? Thanks for the help, Dave I would say that best way is to get actual decorator from element and then set escape option, not to add new decorator: $zend_form_element->getDecorator('Label')->setOption('escape',false); Here is the right way to do it: $zend_form_element->addDecorator('Label', аrray('escape'=>false)); from: http:

Add caching to Zend\\Form\\Annotation\\AnnotationBuilder

孤人 提交于 2019-12-05 12:12:38
As I've finally found a binary of memcache for PHP 5.4.4 on Windows, I'm speeding up the application I'm currently developing. I've succeeded setting memcache as Doctrine ORM Mapping Cache driver, but I need to fix another leakage: Forms built using annotations. I'm creating forms according to the Annotations section of the docs . Unfortunately, this takes a lot of time, especially when creating multiple forms for a single page. Is it possible to add caching to this process? I've browsed through the code but it seems like the Zend\Form\Annotation\AnnotationBuilder always creates the form by

Set Zend\\Form Error Messages from Controller

自作多情 提交于 2019-12-05 07:43:25
this is probably a very simple task, but currently I'm failing horribly at it. I just want to add a custom error to my form when my authentication fails. What i tried $form->setMessages(array( array('password' => $this->failedLoginMessage) )); Unexpected Result \Zend\Debug\Debug::dump($form->getMessages()); array(0) {} If i understand the code correctly this should attach an error message to the password element. Actually looking at the setMessages i thought attaching a single-dimension array should have been enough, but it needs the 2nd dimension, too :S I'm just stuck on that simple task,

Zend form setRequired(true) or addValidator(NotEmpty)

拥有回忆 提交于 2019-12-05 00:33:40
Is there any real difference between the behavior or output of these 2. They look to me like they do the same thing. ->addValidator('NotEmpty') ->setRequired(true) Yes, there's a difference. If an element is not required, it'll validate even if the whole value is missing from the data you validate against. The value is only validated against registered validators after it's been determined that it exists. NotEmpty validator will only fail if the field is present, but is empty. Also, it's not necessary to add NotEmpty validator yourself, by default Zend auto inserts NotEmpty validator for

Zend_Form_Decorator - How to add attrib to Zend_Form_Element_Hidden?

我的未来我决定 提交于 2019-12-04 20:45:35
I have 2 requirements: 1) All hidden input elements should be affected without removing standard decorators. 2) This should happen WITHOUT having to specify it on a per-element basis. All I need is for a CSS class to be attached to the DT & DD tags IF the element type is Zend_Form_Element_Hidden. I've tried creating custom HtmlTag, DtDdWrapper, and FormElement decorators, but haven't been able to figure out how to do it. By default they appear this way: <dt> </dt> <dd><input type="hidden" name="whatever" value="bling" /></dd> I would like them to appear this way: <dt class="hidden"> </dt> <dd

Override Separator on Zend_Form Radio Elements When Using a ViewScript Decorator

余生颓废 提交于 2019-12-04 19:39:30
I am using ViewScripts to decorate my form elements. With radio elements, the separator can normally be overridden, but the override is being ignored when I use the ViewScript. When I use the below call and ViewScript, the radio elements are separated by a '<br />' rather than the space I've specified. If leave the default decorators, the override works. $this->addElement('radio', 'active', array( 'disableLoadDefaultDecorators' => true, 'decorators' => array(array('ViewScript', array('viewScript' => 'form/multi.phtml'))), 'label' => 'Active', 'required' => true, 'multiOptions' => array('1' =>

Zend Form - How to set values on sub form elements?

淺唱寂寞╮ 提交于 2019-12-04 18:42:06
array 'subQuantity' => array 'quantity_6' => string '23' (length=2) 'quantity_16' => string '23' (length=2) 'quantity_18' => string '23' (length=2) 'update' => string 'Update' (length=6) Good day! I just created a subform from my existing zend form and procures this data when form submits. Based on posted data (the quantity_ elements), I would like to set the values to subform elements. Is it possible? Thanks in advance. cheers and happy coding! Not sure whether you want to set values of individual subform elements or all of them at once. Nevertheless you can use populate method. For example: