zend-validate

zend framework 2 - compare 2 inputs using validator?

依然范特西╮ 提交于 2019-12-12 18:28:09
问题 I'm new to zend framework 2 and I have a question on comparing two inputs in the factory-backed form. My scenario is like following: I want to compare two inputs, for example, $startDate and $endDate . I want to validate that $startDate is always less than $endDate . How I'm going to do this? For example: $inputFilter->add($factory->createInput(array( 'name' => 'startDate', 'required' => true, 'validators' => array( array( 'name' => 'LessThan', 'options' => array( 'max' => $endDate, ), ), ),

Zend Framework - Where should we place our custom Validators?

陌路散爱 提交于 2019-12-12 16:01:29
问题 We can read here how to write: http://framework.zend.com/manual/en/zend.validate.writing_validators.html class MyValid_Float extends Zend_Validate_Abstract { 1) Where should we place this? application/default/validators ? application/view/helpers/... ? 2) Do we have to register this somewhere on our application ? Update: Here's an example of my bootstrap: include_once 'config_root.php'; set_include_path ( $PATH ); require_once 'Initializer.php'; require_once "Zend/Loader.php"; require_once

Zend_Validate_Db_RecordExists with Doctrine 2?

China☆狼群 提交于 2019-12-12 09:42:35
问题 I'm using Doctrine 2 in a Zend Framework application and require functionality similar to Zend_Validate_Db_RecordExists and Zend_Validate_Db_NoRecordExists. For example, when a user enters a new item, I need to validate that a duplicate entry doesn't already exist. This is easy to accomplish with Zend_Db by adding the Db_NoRecordExists validator on my forms. I tried implementing the custom-validator solution proposed here, but I can't figure out how they are communicating with Doctrine to

Zend Validation Db_NoRecordExists and exclude option

自古美人都是妖i 提交于 2019-12-12 08:44:13
问题 I'm trying to use the "exclude" option for a Db_NoRecordExists validator, cause when I'm "editing" the element it always return me back a "duplicated" error, as usual. What I aim to is to tell to the form to keep back the value passed to the form itself from the Controller... This is the Controller: public function editAction() { $id = $this->getRequest()->getParam('id'); $pagesMapper = new Application_Model_PagesMapper(); $form = new Application_Form_PageEdit(); $form->populate($pagesMapper-

ZF2 + Doctrine 2 - Entity created when requirements not met and values empty

南笙酒味 提交于 2019-12-12 05:47:26
问题 Extending on 2 previous questions about form structure and validating collections I've run into the next issue. My form validates properly. Including included collections by way of Fieldsets. But the innermost Fieldset should not result in an Entity and a FK association to the parent if its values are not set. An Address may or may not have linked Coordinates . It's possible to create all of these in the same Form. However, the Coordinates should not be created and should not be linked from

ZF2 inputfilter doctrine NoObjectExists editing object does not validate

爱⌒轻易说出口 提交于 2019-12-11 02:27:11
问题 So i got a ZF2 application, got a Form and a InputFilter in the InputFilter i have: $this->add( array( 'name' => 'email', 'required' => true, 'validators' => array( array( 'name' => 'EmailAddress' ), array( 'name' => 'DoctrineModule\Validator\NoObjectExists', 'options' => array( 'object_repository' => $sm->get('doctrine.entitymanager.orm_default')->getRepository('YrmUser\Entity\User'), 'fields' => 'email' ), ), ), ) ); works great, however when i edit a existing object and save it the

Date validator that validates if the date is greater than or equal to today with Zend Framework

天大地大妈咪最大 提交于 2019-12-10 16:36:45
问题 $form = new Zend_Form(); $mockDate = new Zend_Form_Element_Text('mock'); $mockDate->addValidator(???????); $form->addElements(array($mockDate)); $result = $form->isValid(); if ($result) echo "YES!!!"; else echo "NO!!!"; Assumption that the element is in a date format. How do I determine that the date given is greater than or equal to today? 回答1: You can create a simple validator to do this: class My_Validate_DateGreaterThanToday extends Zend_Validate_Abstract { const DATE_INVALID =

Should validation be done in Form objects, or the model?

我的未来我决定 提交于 2019-12-10 15:42:27
问题 This question is mainly geared towards Zend in PHP, although it certainly applies to other languages and frameworks, so I welcome everyone's opinion. I've only recently been using the Zend framework, and while it's not perfect, I have had a pretty good time with it. One thing that drives me crazy, however, is that most of the examples I see of people using Zend do the validation in special form objects, rather than in the model. I think this is bad practice because data can enter into the

Difference between InputFilterAwareInterface and InputFilterProviderInterface in ZF2

邮差的信 提交于 2019-12-08 03:37:33
Can someone explain me the difference between both interfaces InputFilterAwareInterface and InputFilterProviderInterface? Both seem to serve to the same purpose, to get an InputFilter, but I know they cannot be the same... And when do they get called? Thanks edigu Both interfaces exist for different purposes. The InputFilterAwareInterface guarantees that implemented classes will have a setInputFilter() and getInputFilter() methods which accept and return an InputFilter instance when necessary. On the other hand, the InputFilterProviderInterface guarantees only that implemented classes will

Difference between InputFilterAwareInterface and InputFilterProviderInterface in ZF2

元气小坏坏 提交于 2019-12-08 03:12:03
问题 Can someone explain me the difference between both interfaces InputFilterAwareInterface and InputFilterProviderInterface? Both seem to serve to the same purpose, to get an InputFilter, but I know they cannot be the same... And when do they get called? Thanks 回答1: Both interfaces exist for different purposes. The InputFilterAwareInterface guarantees that implemented classes will have a setInputFilter() and getInputFilter() methods which accept and return an InputFilter instance when necessary.