Created
November 26, 2012 18:48
-
-
Save basz/4149878 to your computer and use it in GitHub Desktop.
Better way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| When an accountNumber has been changed in the form it must be validated for uniqueness. This unique validator can't be used when the value hasn't been modified, because the value isn't unique then... I'm aware that I might write a custom validator, but my question is how do you handle dynamic input filtering on a form. A form for new record probably has different filters then while modifying. | |
| I'm also aware of the validation groups, do those help in this situation? | |
| function editAction() { | |
| ... | |
| if ($this->getRequest()->isPost()) { | |
| $form->setData($this->getRequest()->getPost()); | |
| if ($entity->getAccountNumber() != $form->get('dealer')->get('accountNumber')->getValue()) { | |
| /** @var $chain \Zend\Validator\ValidatorChain */ | |
| $chain = $form->getInputFilter()->get('dealer')->get('accountNumber')->getValidatorChain(); | |
| $chain->addValidator($form->get('dealer')->getUniqueAccountNumberValidator()); | |
| } | |
| if ($form->isValid()) { | |
| .... | |
| // different take, different example | |
| $form->get('user')->setIsPasswordRequiredContext(true); // but MUST be called before setData... | |
| $form->setData($this->getRequest()->getPost()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment