views:

39

answers:

2

i am creating a form with a check box called "agreement", the user must click this to confirm that he has agreed to the agreements. But how do i add this to the validation? can i do this from the model? this is a field that is not in the database.

im stuck here.

+1  A: 

You can manually validate the field if you want to.

$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 validation in the model, which is probably preferable. For this I would write my own validation function which checks to see if the data exists and matches your form value.

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

DavidYell
+1  A: 

Personally, I'd check with javascript before submitting the form, then check again in the controller just before the save().

My reasoning for this is that agreement is not really related to the datamodel as it isn't a stored value (and only has one valid condition, so validation is meaningless), but is a condition of form submission. If it was a column in the table or was used to generate or modify a stored value, then I'd probably do it on the model.

Leo