I am new to cakephp and trying to write a simple application with it, however I am stuck with some form validation issues.
I have a model called "Man" that has many "PersonSkill" objects. To add PersonSkill to a person, I set it to call a URL, for example:
http: // localhost / myapp / person_skills / add / person_id: 3
I went through person_id because I want to display the name of the person for whom we are adding skills.
My problem is that if the check fails, the person_id parameter is not saved for the next request, so the username is not displayed.
The add method on the controller is as follows:
function add() {
if (!empty($this->data)) {
if ($this->PersonSkill->save($this->data)) {
$this->Session->setFlash('Your person has been saved.');
$this->redirect(array('action' => 'view', 'id' => $this->PersonSkill->id));
}
} else {
$this->Person->id = $this->params['named']['person_id'];
$this->set('person', $this->Person->read());
}
}
person_skill add.ctp , person_id, :
echo $form->input('person_id', array('type'=>'hidden','value'=>$person['Person']['id']));
URL- person_id, , , ?
.