zend-form-element

How to remove a validator from a Form Element / Form Element ValidatorChain in Zend Framework 2?

一个人想着一个人 提交于 2019-11-30 22:01:53
I read this question on SO: " how to disable inArray validator forms in zend framework2 " and was trying to find it out, but couldn't find any way to detach/remove the InArray Validator. But InArray is just a validator. So how can remove a validator from the validator list of a form element? I can get the validators: $myElement = $form->getInputFilter()->get('city'); $validatorChain = $cityElement->getValidatorChain(); $validators = $validatorChain->getValidators(); and maybe can then unset the array element with the validator, I want to remove, and then pass the result array back to the Input

Zend validators and error messages: addValidator and addErrorMessage

岁酱吖の 提交于 2019-11-30 15:14:29
If I have a form element that has multiple validators attached to it (3 in this example), how would I use addErrorMessage to create custom error messages when each unique validator fails. Is there a way to add a custom message for each validator? $element = new Zend_Form_Element_Text()... $element->.... ->addValidator(...) ->addValidator(...) ->addValidator(...) ->addErrorMessage() Typically it's done per validator error message, not per validator... $element->setErrorMessages(array(Zend_Validate_...::CONSTANT => 'New Message')); But I often prefer to override all of an element's errors to a

How do configure Zend_Form to use array notation?

 ̄綄美尐妖づ 提交于 2019-11-29 22:10:07
问题 I'm having difficulty configuring Zend_Form. I have a Zend_Form sub-class. The form has some required information and some additional information. I want the additional information to be accessible via an array. The submitted data will look something like this: $formData['required1'] $formData['required2'] $formData['addiotnalData']['aData1'] $formData['addiotnalData']['aData2'] I've Googled this and tried all the suggestions I've found (using subForms and setting the Zend_Form::setIsArray(

Zend Framework: Working with Form elements in array notation

…衆ロ難τιáo~ 提交于 2019-11-29 05:35:06
I would like to be able to add a hidden form field using array notation to my form. I can do this with HTML like this: <input type="hidden" name="contacts[]" value="123" /> <input type="hidden" name="contacts[]" value="456" /> When the form gets submitted, the $_POST array will contain the hidden element values grouped as an array: array( 'contacts' => array( 0 => '123' 1 => '456' ) ) I can add a hidden element to my form, and specify array notation like this: $form->addElement('hidden', 'contacts', array('isArray' => true)); Now if I populate that element with an array, I expect that it

Zend Framework 2 - Form Element Decorators

有些话、适合烂在心里 提交于 2019-11-28 18:57:42
I want to force the Zend form into Twitter Bootstrap style. I currently iterate through the form fields and write the form info into my bootstrap div construction. I saw in Zend Framework 1(!) that there is a way to do this within a decorator. But for some reason the doc for version 2 doesn't cover this point... I'd like to do something like this: protected $_format = '<label for="%s">%s</label>' . '<input id="%s" name="%s" type="text" value="%s"/>'; public function render($content) { $element = $this->getElement(); $name = htmlentities($element->getFullyQualifiedName()); $label = htmlentities

How to print a group display individually from its content?

与世无争的帅哥 提交于 2019-11-28 02:20:16
I'm using Zend Framework and Zend_Form to render my form. But as I found it hard to customize it, I decided to print elements individually. Problem is, I don't know how to print individual elements inside a display group. I know how to print my display groups (fieldsets) but I need to add something inside it (like a <div class="spacer"></div> to cancel the float:left . Is there any way to display the group only without its content so I can print them individually myself? Thank you for your help. What you are looking for is the 'ViewScript' decorator. It allows you to form your html in any way

Zend Framework: Working with Form elements in array notation

情到浓时终转凉″ 提交于 2019-11-27 23:30:03
问题 I would like to be able to add a hidden form field using array notation to my form. I can do this with HTML like this: <input type="hidden" name="contacts[]" value="123" /> <input type="hidden" name="contacts[]" value="456" /> When the form gets submitted, the $_POST array will contain the hidden element values grouped as an array: array( 'contacts' => array( 0 => '123' 1 => '456' ) ) I can add a hidden element to my form, and specify array notation like this: $form->addElement('hidden',

Zend Framework 2 - Removed form element causes validation to fail

…衆ロ難τιáo~ 提交于 2019-11-27 23:15:52
I use a certain form in several places. In one of them I need to ignore a form element which I set programmatically after the validation. Because it's just an exception I don't want to create a new form. So I thought, I just remove this element in the controller like: $myForm->remove('myElement'); The problem is that the form now won't validate. I don't get any errors but the $myForm->isValid() just returns an empty value. Any ideas what I might be doing wrong? Thanks! Ok, finally I found a solution ! You can define a ValidationGroup which allows you to set the attributes you'd like to

Zend Framework 2 - Removed form element causes validation to fail

拈花ヽ惹草 提交于 2019-11-27 04:40:03
问题 I use a certain form in several places. In one of them I need to ignore a form element which I set programmatically after the validation. Because it's just an exception I don't want to create a new form. So I thought, I just remove this element in the controller like: $myForm->remove('myElement'); The problem is that the form now won't validate. I don't get any errors but the $myForm->isValid() just returns an empty value. Any ideas what I might be doing wrong? Thanks! 回答1: Ok, finally I

How do I use ViewScripts on Zend_Form File Elements?

元气小坏坏 提交于 2019-11-27 00:47:10
I am using this ViewScript for my standard form elements: <div class="field" id="field_<?php echo $this->element->getId(); ?>"> <?php if (0 < strlen($this->element->getLabel())) : ?> <?php echo $this->formLabel($this->element->getName(), $this->element->getLabel());?> <?php endif; ?> <span class="value"><?php echo $this->{$this->element->helper}( $this->element->getName(), $this->element->getValue(), $this->element->getAttribs() ) ?></span> <?php if (0 < $this->element->getMessages()->length) : ?> <?php echo $this->formErrors($this->element->getMessages()); ?> <?php endif; ?> <?php if (0 <