How to check an additional field in a form? Cakephp

I am creating a form with an agreement flag. The user must click on it to confirm that he has agreed to the agreement. But how to add this to the check? Can I do this from a model? This is a field that is not in the database.

I'm stuck here.

+4
source share
2 answers

You can manually confirm the field if you wish.

$this->Model->set($this->data['Form']['agree']); if($this->Model->validates($this->data)){ // okay $this->Model->Save(); }else{ pr($this->Model->invalidFields()); } 

Or you can do a manual check in a model, which is probably preferable. To do this, I would write my own validation function, which checks if data exists and matches your form value.

http://book.cakephp.org/view/1181/Adding-your-own-Validation-Methods

+2
source

Personally, I check with javascript before submitting the form, and then check the controller again before loading ().

My reasoning for this is that the convention is really not related to the datamodel, since it is not a stored value (and has only one valid condition, so validation does not make sense), but it is a condition for the presentation of the form. If it was a column in a table or was used to create or modify a stored value, I would probably do it on a model.

+1
source

All Articles