Hi all!
I'm creating a form with data from two different models. (Team and
Coach).
The save is working fine, except for displaying error data for the
Player model.
Here goes my code:
## Controller
function add() {
if (empty($this->data)) {
$this->render();
} else {
$this->Team->create();
$this->Team->Coach->create();
// Setting Team data this way so that
validation is processed correctly
$this->Team->set($this->data);
$this->Team->Coach->set($this->data);
if ($this->Team->validates() && $this->Team-
>Coach->validates()) {
$this->Team->save();
$team_id = $this->Team->getLastInsertID();
$this->data['Coach']['team_id'] = $team_id;
$this->Team->Coach->set($this->data);
$this->Team->Coach->save();
$this->Session->setFlash('The Team has been
saved');
$this->redirect("/teams/view/
$team_id");
} else {
$this->Session->setFlash('Please
correct errors below.');
}
}
}
## View - First model data. For this one, validation errors are
diplayed.
<div>
<dl>
<dt><?php echo $form->labelTag('Team/city', 'Local');?></dt>
<dd><?php echo $html->selectTag('Team/city', array('Capital'
=> 'São Paulo Capital', 'Interior' => 'São Paulo Interior' ));?></dd>
</dl>
</div>
## View - Second model data. Here the validation errors are not
diplayed
<div>
<dl>
<dt><?php echo $form->labelTag('Coach/name', 'Nome');?></dt>
<dd><?php echo $html->input('Coach/name', array('size' =>
'60'));?></dd>
<?php echo $html->tagErrorMsg('Coach/name', 'Please enter the
Name.');?>
</dl>
</div>
When a validation for Coach fails, it redisplays the form and the
Flash message, but not the error messages. What's happening?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---