Page 1 of 1

Cake PHP beforeSave()

Posted: Mon Jan 10, 2011 4:36 am
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?

Re: Cake PHP beforeSave()

Posted: Mon Jan 10, 2011 5:17 am
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?

Re: Cake PHP beforeSave()

Posted: Wed Jan 26, 2011 6:59 pm
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