zend-validate

Using “.” for decimals in zend validator float

微笑、不失礼 提交于 2019-12-07 17:47:44
问题 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. 回答1: You can use

Zend_Validate_Date just doesn't work properly

自古美人都是妖i 提交于 2019-12-07 04:16:55
问题 It appears that Zend_Validate_Date just simply doesn't work properly. For example: $validator = new Zend_Validate_Date(array('format' => 'yyyy')); This is a simple validator that should only accept a four digit year, yet $validator->isValid('1/2/3') returns true! Really, Zend? Or how about this: $otherValidator = new Zend_Validate_Date(array('format' => 'mm/dd/yyyy')); Even with the above code, $otherValidator->isValid('15/13/10/12/1222') returns true too! I'm using Zend Framework 1.11.9. Is

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

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

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

Zend_Validate_Date just doesn't work properly

爱⌒轻易说出口 提交于 2019-12-05 10:42:26
It appears that Zend_Validate_Date just simply doesn't work properly. For example: $validator = new Zend_Validate_Date(array('format' => 'yyyy')); This is a simple validator that should only accept a four digit year, yet $validator->isValid('1/2/3') returns true! Really, Zend? Or how about this: $otherValidator = new Zend_Validate_Date(array('format' => 'mm/dd/yyyy')); Even with the above code, $otherValidator->isValid('15/13/10/12/1222') returns true too! I'm using Zend Framework 1.11.9. Is it just me or is this a really terrible validation class? (UPDATE: In other words, is there something

Zend Form Validate Range Date

孤街浪徒 提交于 2019-12-04 13:18:25
问题 who gives me a hand to create a custom validator for Zend Framework, which checks that a date is in to a range? Example: dateGT = 2011-09-05 dateLT = 2011-07-05 if the form field is set to: dateFieldForm = 2011-08-15 I expect the validator returns true! and if the form field is set to: dateFieldForm = 2011-10-15 I expect the validator returns false! 回答1: Sorry, large code ahead: <?php /** @see Zend_Validate_Abstract */ require_once 'Zend/Validate/Abstract.php'; /** * @category Zend * @package

Zend Form Edit and Zend_Validate_Db_NoRecordExists

余生长醉 提交于 2019-12-04 11:18:27
问题 I am slowly building up my Zend skills by building some utility websites for my own use. I have been using Zend Forms and Form validation and so far have been happy that I have been understanding the Zend way of doing things. However I am a bit confused with how to use Zend_Validate_Db_NoRecordExists() in the context of an edit form and a field that maps to database column that has to be unique. For example using this simple table TABLE Test ( ID INT AUTO_INCREMENT, Data INT UNIQUE ); If I

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

99封情书 提交于 2019-12-03 21:18:10
问题 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

ZF2/Doctrine2 - Fieldsets not validated, data is always valid

强颜欢笑 提交于 2019-12-03 18:15:31
问题 I've set up a structure using Abstract classes for Forms, Fieldsets and InputFilters. Forms and Fieldsets have Factories while InputFilters are created and set on the Fieldsets by the FieldsetFactory (uses the MutableCreationOptionsInterface to pass along options) The problem I have is that InputFilters are loaded for the Form, but are not used to validate the data. All input is accepted as valid. E.g. I have a Country Entity with a name property. The name of the Country must be at least 3