Hi,
I have given validation in model. Also, I have given some validation in controller for checking the captcha code. After that, the application is not displaying the model validation errors. If I comment the controller code, model validation is working fine and displaying the errors. Both not working..
Model code (sample)
class User extends AppModel {
var $name = 'User';
var $validate = array(
'username' => 'notempty',
'firstname' => 'notempty'
);
}
Controller code
if (!empty($this->data)) {
$this->User->set($this->data);
$this->User->create();
$captcha = $this->Session->read('CAPTCHA_CODE');
if (strtolower($captcha) != strtolower($this->data['User']['captcha']))
{
$this->User->invalidate('captcha', __('Sorry, your entry did not match', true));
}
if ($this->User->save($this->data, array('validate' => 'only')))
{
if ($this->User->save($this->data, array('validate' => 'false'))) {
$this->Session->setFlash(__('Registered successfully', true));
$this->redirect('success');
}
}else {
$this->Session->setFlash(__('Please, try again.', true));
}
}
I have replaced the "if ($this->User->save($this->data, array('validate' => 'only')))" line with if ($this->User->validates()), then also it is not working.
please help