Something like this should work:
(code not tested, but theory sound)
class Customer extends AppModel {
var $validate = array(
'country_id' => array(
array(
'rule' => array('custom', '/^[a-z]{2}$/'),
'required' => true,
'message' => 'Please select the country that you reside in.'
),
array(
'rule' => array('checkCountry'),
'message' => Please stop playing with firebug.'
),
)
);
function checkCountry($data) {
$countryCode = reset($data);
return $this->Country->hasAny(array('Country.code' =>
$countryCode));
}
}
hth
grigri
On Feb 4, 7:01 am, Braindead <[email protected]> wrote:
> Brian, your solution seems to be ok, but there is one problem:
>
> Let's assume the selectbox contains the 3 items de, nl and dk.
> Selecting one of the items would pass the validation.
> But aa, ab, ac, ad, ae and so on would also pass the validation
> without being valid.
>
> So what is the way to go? I guess you have to write a custom
> validation rule, that checks if the selected item is part of the
> association.
>
> Hope that helps.
> Markus
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---