On Tue, Feb 3, 2009 at 2:40 PM, Mickiii <michael.la...@gmail.com> wrote: > > Hi, > > I am trying to validate data from an association the I output to the > view like: > > $this->set('countries', $this->Customer->Country->find('list')); > > and in the view: > > echo $form->input('Customer.country'); // Results in select > > How would I validate the input of this form? I was thinking I could > use "inList", but that does not seem to provide this functionality. >
It depends on the primary key you're using for Country. I use the ISO code, others might use an auto-increment field. Either way, just check that Customer.country_id is not empty and conforms to whatever kind of PK you're using. ** I just noticed that your field is "country" not "country_id". The latter is the way Cake would expect it by default. ** In your Customer's $validate array ... 'country_id' => array( 'rule' => array('custom', '/^[a-z]{2}$/'), 'required' => true, 'message' => 'Please select the country that you reside in.' ) or, for integer PK: 'country_id' => array( 'rule' => array('custom', '/^[0-9]+$/'), 'required' => true, 'message' => 'Please select the country that you reside in.' ) --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---