I have a form that i use to register and update data. It works fine, but when i update the data, the model validation returns false, because the value inserted already exists.
I have the following code:
/* Validation Rule*/
public $validate = array(
'unique' => array(
'rule' => array('unique', 'field in the table'),
'message' => 'The field cannot be empty.'
)
...
)
/* Function that check if the value already exists */
public function unique($value, $field) {
$check = $this->find('count', array(
'recursive' => -1,
'conditions' => array(
$this->Alias.$field => $value
)
));
return $check == 0;
}
So, how can i disable the unique rule, but keeping the other rules?
You can add on in your validation rules and accept this validation only on create:
public $validate = array(
'unique' => array(
'rule' => array('unique', 'field in the table'),
'message' => 'The field cannot be empty.',
'on' => 'create'
);
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With