What is the most effective way to use DoctrineModule\Validator\NoObjectExists
validator in a Zend Form that is used for editing also? Because when I use the same Form for saving edited values, this validates the Object existence and flags form is invalid.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Few weeks ago I resolved the same problem using a helper method in my custom filter. I am not sure if this is the correct approach but it works.
Zend\InputFilter\InputFilter
.init()
method of filter.So,
Finally, append this inputfilter to your form when editing:
When creating:
I tried using DoctrineModule\Validator\NoObjectExists in form and it prevents updates which keep the unique field(s) unchanged. As @Tadej mentioned - use UniqueObject. Here is an example form:
Note the use of 'use_context' option - it must be used if field is not primary key. 'messages' is optional.
You can't use NoObjectExists in an easy way, you should use UniqueObject instead:
https://github.com/doctrine/DoctrineModule/blob/ea9e6902fd24906250d01d31561454451a788f86/src/DoctrineModule/Validator/UniqueObject.php