Re: Validation from both model and controller not working

2010-03-24 Thread cricket
I'm not 100% sure of this, but I think that the automatic validation
done from save() is overwriting the model's $validationErrors. In any
case, what you should be doing is only calling save() if the
captcha_code matches. So, use an if/else block:

if (strtolower($captcha) != strtolower($this->data['User']
['captcha']))
{
$this->User->invalidate('captcha', __('Sorry, your entry did not
match', true));
$this->Session->setFlash(__('CAPTCHA code does not match', true));
}
else
{
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));
}
}

On Mar 24, 9:31 am, Binu  wrote:
> 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

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Validation from both model and controller not working

2010-03-24 Thread Binu
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

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.