cakephp - Form validation for relational elements -


i have form in cakephp save information multiple models. first model "world", have no problem these fields validation correct , it's saved correctly database. second model "country", use this:

echo $this->form->input('country.0.name'); 

this correctly saved database, there no validation (like stairs required fields) , no automagic (autodetection of content type). third model "region", use same code second 1 there no validation, no automagic , no saving...

can ?

thank you, sébastien

without seeing rest of code, guessing trying save multiple countries @ same time. model expects data come in specific format:

$this->data['model']['field']; 

what passing is:

$this->data['model'][0]['field']; 

the model cannot interpret it. way resolve build foreach when collect data , send each request independently.

foreach($country $field) {    $data['country']['field'] = $field;    // add other fields required     if($this->country->validates($data)) {       $this->country->create();       $this->country->save($data);    } else {       // error handling    } } 

good luck , happy coding!


Comments