Using validator (greaterThan) to refer to another element in form

3 messages Options
Embed this post
Permalink
asgeo1

Using validator (greaterThan) to refer to another element in form

Reply Threaded More More options
Print post
Permalink
Hi,

I'm new to learning the Zend Framework, and are having trouble understanding how one would use the greaterThan validator to check that a Zend_Form_Element_Date element is greater than another Zend_Form_Element_Date in the same form.

First I find that greaterThan doesn't know how to compare dates and is actually just comparing strings which is lame.

Secondly, with these validators, there does not appear to be anyway to make them compare the value of a form element to the value of another form element.

Other than to subclass Zend_Validate_GreaterThan and add my own support for this, I can't see anyway to get around this.

I hope someone tells me I'm just doing this all wrong.

Thanks,
-adam
lightflowmark

Re: Using validator (greaterThan) to refer to another element in form

Reply Threaded More More options
Print post
Permalink
Hi,

1)  ISO dates can be compared as strings, that's one of the main point of the formats - 2009-06-30 > 2009-05-01.  You should use a filter to convert your dates to this format anyway

2) You need to write a custom validator to compare 2 fields in a form; it's very easy, see the example on
http://framework.zend.com/manual/en/zend.form.elements.html (1/3 of the way down, "Validation Context"

Yours,
Mark







asgeo1 wrote:
Hi,

I'm new to learning the Zend Framework, and are having trouble understanding how one would use the greaterThan validator to check that a Zend_Form_Element_Date element is greater than another Zend_Form_Element_Date in the same form.

First I find that greaterThan doesn't know how to compare dates and is actually just comparing strings which is lame.

Secondly, with these validators, there does not appear to be anyway to make them compare the value of a form element to the value of another form element.

Other than to subclass Zend_Validate_GreaterThan and add my own support for this, I can't see anyway to get around this.

I hope someone tells me I'm just doing this all wrong.

Thanks,
-adam
asgeo1

Re: Using validator (greaterThan) to refer to another element in form

Reply Threaded More More options
Print post
Permalink
Thanks Mark,

Your information was helpful. I now have a working custom validator extending GreaterThan which can validate a date against another form element correctly.

Regards,
-adam


lightflowmark wrote:
Hi,

1)  ISO dates can be compared as strings, that's one of the main point of the formats - 2009-06-30 > 2009-05-01.  You should use a filter to convert your dates to this format anyway

2) You need to write a custom validator to compare 2 fields in a form; it's very easy, see the example on
http://framework.zend.com/manual/en/zend.form.elements.html (1/3 of the way down, "Validation Context"

Yours,
Mark







asgeo1 wrote:
Hi,

I'm new to learning the Zend Framework, and are having trouble understanding how one would use the greaterThan validator to check that a Zend_Form_Element_Date element is greater than another Zend_Form_Element_Date in the same form.

First I find that greaterThan doesn't know how to compare dates and is actually just comparing strings which is lame.

Secondly, with these validators, there does not appear to be anyway to make them compare the value of a form element to the value of another form element.

Other than to subclass Zend_Validate_GreaterThan and add my own support for this, I can't see anyway to get around this.

I hope someone tells me I'm just doing this all wrong.

Thanks,
-adam