zend-form

How to validate a field of Zend_Form based on the value of another field?

好久不见. 提交于 2019-12-06 03:01:44
I'm trying to add a custom validator to a field. It should take into account the value of another field. E.g. field A should be at most B+50%. I've made a class implementing Zend_Validate_Interface , but apparently Zend Form only sends in the value of the current field to the validator. How do I make the validator receive everything? When you call isValid on a Zend_Form it will pass the all the data you passed to the method $form->isValid(array('a' => 1, 'b' => 2)); Your custom validator will receive that whole array of raw values. Example Validator class My_Validator_TwoVals implements Zend

Zend Framework Zend_Form Decorators: <span> Inside Button Element?

核能气质少年 提交于 2019-12-06 02:23:57
问题 I have a button element that I've created like so: $submit = new Zend_Form_Element_Button('submit'); $submit->setLabel('My Button'); $submit->setDecorators(array( 'ViewHelper', array('HtmlTag', array('tag' => 'li')) )); $submit->setAttrib('type', 'submit'); This generates the following HTML: <li> <label for="submit" class="optional">My Button</label> <button name="submit" id="submit" type="submit">My Button</button> </li> I would like to wrap the inside of the button with a <span>, like this:

Change Fieldset Fields' required parameter dynamically

大兔子大兔子 提交于 2019-12-06 02:08:07
问题 I have a moneyFieldset with 2 fields, amount and currency. class MoneyFieldset ... { public function __construct($name = null, $options = array()) { parent::__construct($name, $options); $this->setHydrator(...); $this->add(array( 'name' => 'currency', 'type' => 'select', 'options' => array( 'value_options' => \Core\Service\Money::getAvailableCurrencies(true), ), 'attributes' => array( 'value' => \Core\Service\Money::DEFAULT_CURRENCY, ), )); $this->add(array( 'name' => 'amount', 'type' =>

Custom meaningful error message for Zend RegEx Validator

独自空忆成欢 提交于 2019-12-05 23:35:59
问题 I'm validating a text field in my form as follows: $name = new Zend_Form_Element_Text('name'); $name->setLabel('First Name:') ->setRequired(true) ->addFilter(new Zend_Filter_StringTrim()) ->addValidator('regex',true,array('/^[(a-zA-Z0-9)]+$/')) ->addErrorMessage('Please enter a valid first name'); What I'm trying to accomplish is - how can i display a meaningful error message? Eg: If first name is 'XYZ-', how can i display '- is not allowed in first name.' Is there a way I can access what

Using “.” for decimals in zend validator float

独自空忆成欢 提交于 2019-12-05 21:16:43
I have a form with a element called "price". I validate this element with the "float" validator. The thing is when I insert, for example: 12,50 => it is valid but when I try to save it on the DB (mysql) it is saved as "12.00" So I wanna to change the decimal character from "," to ".". Does anybody knows how?? Note. If I put: $price->addValidator('Float', 'de') or $validator = new Zend_Validate_Float(array('locale' => 'de')); $price->addValidator($validator) It does not work. You can use a filter Zend_Filter LocalizedToNormalized to it will normalized you localized price according to the user's

How to add CSS classes to Zend_Form_Element_Select option

岁酱吖の 提交于 2019-12-05 20:16:11
I'm trying to add a CSS class to a Zend_Form_Element_Select option, but I just can't find a way to do it. The desired output would be something like this: <select name="hey" id="hey"> <option value="value1" style="parent">label1</option> <option value="value2" style="sibling">sublabel1</option> <option value="value3" style="sibling">sublabel2</option> <option value="value4" style="parent">label2</option> <option value="value5" style="sibling">sublabel3</option> <option value="value6" style="sibling">sublabel4</option> </select> But I'm getting this: <select name="hey" id="hey"> <option value=

Disable notInArray Validator Zend Framework 2

这一生的挚爱 提交于 2019-12-05 18:09:53
问题 Is there a way to disable notInArray Validator in Zend Framework 2. All the info on the internet shows how to disable the notInArray Validator in Zend Framework 1, for example in this fashion If you do not want the InArray validator at all, you can disable this behavior by either calling setRegisterInArrayValidator(false) on the element, or by passing false to the registerInArrayValidator configuration key on element creation. One the posts in stackoverflow can be found here Unfortunately

How can I customise Zend_Form regex error messages?

不羁岁月 提交于 2019-12-05 17:49:43
I have the following code: $postcode = $form->createElement('text', 'postcode'); $postcode->setLabel('Post code:'); $postcode->addValidator('regex', false, array('/^[a-z]{1,3}[0-9]{1,3} ?[0-9]{1,3}[a-z]{1,3}$/i')); $postcode->addFilters(array('StringToUpper')); $postcode->setRequired(true); It creates an input field in a form and sets a regex validation rule and works just fine. The problem is that the error message it displays when a user enters an invalid postcode is this: 'POSTCODE' does not match against pattern '/^[a-z]{1,3}[0-9]{1,3} ?[0-9]{1,3}[a-z]{1,3}$/i' (where input was POSTCODE)

Validating multiple optional form fields with Zend Framework

ぃ、小莉子 提交于 2019-12-05 17:28:21
I am trying to validate Zend_Form which has several optional fields and I want at least one of them to be filled in. In my case I have mobile, home and office phone numbers and I want at least one of them to be provided. I am trying to achieve this though Validation Context (as suggested here ) by creating custom validator which extends Zend_Validate_Abstract. The problem is that if all optional fields are empty they are missing from the form $context (passed to the validator class) and this way not validated at all. So if you fill any or several of the three options (mobile, home, work) they

Pass variable into Zend Form

試著忘記壹切 提交于 2019-12-05 16:25:28
I have a zend form instantiated $form = Form_Example(); Now I want to pass an ID from my controller to my form. So I did this: $form = Form_Example(array('id' => $id)); Inside the form I try to call it through: $this->id But it isn't there. Anybody knows how to get that id into the form? Thanks Make sure you have setter for the the element, in your case public function setId($id) . Zend_Form constructor checks if setter method exists for the property, if it exists then it is called, otherwise it sets the attribute of the form, see setAttrib($key, $value) . The end result will be something like