Cake PHP beforeSave()

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Post Reply
devilinc
Forum Newbie
Posts: 16
Joined: Fri Nov 12, 2010 1:07 am

Cake PHP beforeSave()

Post by devilinc »

i want to check a condition when the user enters a text field input in the form....i want to check that the value doesnt exceed a value already listed...i run this condition before if($this->save($this->data))....what happens on submission is that the condition succeeds BUT the form entries entered by customer gets wiped out completely and he has to enter from scratch....what do i do??? please help.....saw a beforeSave() ran it but I think I am running it the wrong way....i just enter the conditon test inside beforeSave() written in my model.....but i dont make a call to it in the controller....so could anyone guide me?
devilinc
Forum Newbie
Posts: 16
Joined: Fri Nov 12, 2010 1:07 am

Re: Cake PHP beforeSave()

Post by devilinc »

ok now i get the beforeSave() working correctly with my form values still there but my url is changed now....i pass an id also with the url but now the id is not present and hence my function never runs and i get the form with the values entered back to me.........it doesnt save...what am i doing wrong?
endyourif
Forum Newbie
Posts: 7
Joined: Wed Jan 26, 2011 6:53 pm

Re: Cake PHP beforeSave()

Post by endyourif »

You should be implementing a validation array in your model. This will be automatically called when you call the save() function in your controller. Check out the cook book here: http://book.cakephp.org/view/1143/Data-Validation
Post Reply