Reputation: 201
In my Patients 'view' page I replaced a div with 'doctors/add' using ajax. And now I can add a doctor in Patients view page. But if any validation error occured it goes directly from my Patients view page. to 'doctors/add' page showing validation messages.
I Want it stay on the current page showing validation messages appropriately on input fields of 'add'.
function add() {
if (!empty($this->data)) {
$this->Doctors->create();
if ($this->Doctors->save($this->data)) {
$this->Session->setFlash(__('The Doctor has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The Doctor could not be saved. Please, try again.', true));
}
}
}
Is this due to $this->Session->setFlash in add() ? thanks...!
Upvotes: 2
Views: 5127
Reputation: 1333
Can you pls try this?
function add() {
if (!empty($this->data)) {
$this->Doctors->create();
if ($this->Doctors->save($this->data)) {
$this->Session->setFlash(__('The Doctor has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The Doctor could not be saved. Please, try again.', true));
$this->redirect(array('controller'=>'patient_controller_name', 'action' => 'view'));
}
}
}
Upvotes: 0