cakephp validation
I use validation in model like this
'email' => array(
//'UniqueMail'=>array('rule' => array('checkEmailUnique', 'email' ),'message' => 'mail is used'),
'email'=>array('rule' => 'email','message' => 'mail not valid')开发者_JAVA百科,
'notEmpty'=>array('rule' => 'notEmpty','message' => '*'),
)
and this validation for field email but in some other form idon't want to check the unique mail validation . how i can solve this?
regards
Do not add that rule to your $validates array.
Create a beforeValidate()
callback in your model.
In the beforeValidate()
callback check for the presence of a flag in the form data (something like $data[$this->alias]['checkMail']
. If the flag is set, then add the email validation rule to your $this->validates
array. This will prevent you from validating against that rule unless you specifically tell the model to do so.
try this code
'email' => array(
'mail' => array(
'rule' => array('email', true),
'required' => false,
'message' => 'Not correct e-mail!'),
'unique' => array(
'rule' => 'isUnique',
'message' => 'E-mail was registered!')),
精彩评论