Tuesday, April 27, 2010

Validate array data

Hello,

Can I validate an array that looks like this somehow with the standard
validation rules?

[Trip]
[Passengers]
[1] => Array
(
[passenger_firstname] =>
[passenger_lastname] =>
[passenger_date_of_birth] => 1970-01-01
[passenger_gender] =>
[passenger_nationality] => GB
)
[2] => Array
(
[passenger_firstname] =>
[passenger_lastname] =>
[passenger_date_of_birth] => 1970-01-01
[passenger_gender] =>
[passenger_nationality] => GB
)

I need to write a rule to ensure that firstname & lastname isn't
empty, date of birth is within certain ages etc.

My current rule looks like this:

var $validatePassenger = array(
'passenger_firstname' => array(
array('rule' => array('validateArrayBetween', 1, 30)),
),
'passenger_lastname' => array(
array('rule' => array('validateArrayBetween', 1, 30)),
),
);


but it doesn't work since it requires passenger_firstname to be
directly under [Trip] (or so I think?)

Can someone help me out here...?

Thanks,
Jonas

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: