views:

29

answers:

1

Hi

I'm working on a system and i have a form where i need to do cross validations. By cross validation i mean : if someone is from the united states the system must be able to check if the state that have been selected is a valid united states state and not a canadian province. Ideally, the error output message should be beside the fautive field. (i use default zend_form decorators)

At this stage i'm looking to avoid ajax to be sure that my php fallback work in the case where the user has disabled javascript. In the future i will reload the list and display states/provinces acording to the country.

+3  A: 

You should write a custom validator for this task and add this validator to the state element.

In your validator's isValid method, the second parameter passed is an array of all of the form values. You can then cross-reference the state and country to make sure it is valid.

Validation context is explained in the Reference Guide where their example is comparing two password fields, but you should be able to apply the same principle to your code.

David Caunt
Found the explanation on how to implement the information in the reference guide at http://mnshankar.wordpress.com/2010/02/27/custom-validators-in-zend-form/
Jeff