Reputation: 3
Hi I'm new using CakePHP 2.6.3, I have a problem with the validation of some models.
I populate two different combo box with the same information, how can I validate that when I insert they don't have the same value.
Thanks in advance.
EDIT:
class Requisitoscurso extends AppModel {
public $validate = array(
'requisito' => array(
'required' => array(
'rule' => array('isUnique', array('requisito', 'cod_curso'), false), //sirve cuando se crea y no se pega con error, al editar deja repetir un requisito ya existente
'message' => 'El requisito ya existe.')
)
);
}
Upvotes: 0
Views: 108
Reputation: 633
Maybe some custom validation like this:
public $validate = array(
'someField1' => array(
'rule' => array('cantBeSame'),
'message' => 'someField1 cant be the same as someField2.'
),
'someField2' => array(
'rule' => array('cantBeSame'),
'message' => 'someField2 cant be the same as someField1.'
)
)
public function cantBeSame(){
return ( $this->data['Somemodel']['someField1'] != $this->data['Somemodel']['someField2'] );
}
Upvotes: 1