Hi there,

if you set required to true on your Zend_Form_Element an automatic
Zend_Validate_NotEmpty (not 100% sure about the name and a I'm currently
under way so I cannot look up the manual) validator is inserted into the
validation chain with breakChainOnFailure = true. That means your validator
will not be fired up because the validation chain fails on the NotEmpty
validator.
You can set autoInsertNotEmptyValidator (not sure about the name - just look
up the manual) to false when creating the Zend_Form_Element to change this
behavior (either by specifying the corresponding configuration key in the
constructor or factory method or by using the appropriate setter on the
element itself).

Best regards

Stefan

-----Ursprüngliche Nachricht-----
Von: joostvanveen [mailto:jo...@accentwebdesign.nl] 
Gesendet: Freitag, 22. Mai 2009 10:54
An: fw-general@lists.zend.com
Betreff: [fw-general] Custom validator not run when a Zend_Form field is
empty?


I have written a custom validator that throws an error if the user did not
enter a valid URL or uploaded a media file. 

I have attached this validator to the URL field. It works fine, but ONLY run
if the visitor entered a value in the URL field. If the visitor leaves the
URL field empty the validator does not fire.
$this->getElement('med_url')->addValidator('UrlOrFile');

Is this expected behaviour?
Is there a way I can make sure the validator fires even if the URL field is
left empty?

(I worked around the problem for now by attaching the validator to a hidden
field that always has a value, but this is is a very ugly workaround)
-- 
View this message in context:
http://www.nabble.com/Custom-validator-not-run-when-a-Zend_Form-field-is-emp
ty--tp23666798p23666798.html
Sent from the Zend Framework mailing list archive at Nabble.com.


Reply via email to