Reputation: 1533
I have a form in cakephp 2.5. If a save button is clicked, the record is updated with all validation applicable
If a spam button is clicked the form is submitted with a flag to mark the record as deleted. If in this case the email address is not a valid one, the form will not submit because the validation set from the model is not passed. Is there any way to remove the validation on the fly?
I've looked into using $this->validator()->remove('email');
but this is no use as the validation is already set before the view is rendered.
Upvotes: 1
Views: 978
Reputation: 31
Why don't you use validation rules on your controller instead?
This way, you can leave the rules on the model, but only use them a condition is fullfiled
if ($this->ModelName->validates()) {
// it validated logic
} else {
// didn't validate logic
$errors = $this->ModelName->validationErrors;
}
Or you can disable validation by simply
if ($this->ModelName->saveAll(
$this->request->data, array('validate' => false)
)) {
// saving without validation
}
Upvotes: 1