Wednesday, September 13, 2006

How To Validate data Without Saving?

You know, CakePHP check data only when you saving:

$this -> User -> save ($this->data)

But if you do not needing to save data?

In this case, you can use this "hint":

if ( $this -> User -> validates ( $this -> data ) )
{
        // OK, good to go

}

else
{
        $this->set( 'data', $this->params['data'] );
        $this->validateErrors( $this->User );
        $this->render();

}

This code snippet made by Devo.

2 Comments:

Blogger Kyle Decot said...

awesome tip. I have just started using cakePHP and I was completely lost on how to do this.

12:53 AM  
Blogger Costis Panagiotopoulos said...

This comment has been removed by the author.

6:56 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home