Reputation: 20555
so if i have the following validation rule in my Forward
model
public $validate = array(
'url' =>array(
'rule' => 'url',
'message' => 'Please supply a valid Url.'
)
);
and i want to display the message in a flash how do i achieve that?
I have tried the following:
$new_forward = $this->request->data;
$this->Forward->create();
$this->Session->setFlash($this->Forward->save($new_forward));
Also tried this with no result
$this->Session->setFlash($this->ModelName->validationErrors);
Upvotes: 0
Views: 50
Reputation: 27364
You can do this using below sample code,
$this->Forward->create();
if ($this->Forward->save($this->request->data))
{
$this->Session->setFlash(__('The Forward has been saved', true),'flash_success');
$this->redirect(array('controller' => 'forwards','action' => 'index'));
}
else
{
$this->Session->setFlash(__('The Forward could not be saved. Please, try again.', true),'flash_error');
}
Upvotes: 1