For some reason my custom validation function that I have in my rules array are not being called. I have a model for a form with the following rules
public function rules()
{
return array(
// username and password are required
array('business_name,first_name,last_name,phone_number,re_email,street_address,city,state,zip_code,sub_domain,terms', 'required'),
// check email format
array('email', 'email', 'checkMX'=>true),
// email needs to be authenticated
array('email', 'authenticate_email'),
// subdomain needs to be authenticated
array('sub_domain', 'authenticate_subdomain'),
// email and re_email must be identical
array('re_email', 'compare', 'compareAttribute'=>'email', 'operator'=>'==', 'message'=>'The email addresses you entered do not match.'),
);
}
All the rules run and work fine except the two CUSTOM rules
array('email', 'authenticate_email'),
array('sub_domain', 'authenticate_subdomain'),
authenticate_email and authenticate_subdomain don’t really do anything yet except just add an error
public function authenticate_email($attribute,$params)
{
Yii::app()->session['here']=1;
if(!$this->hasErrors())
{
$this->addError('email','yep error');
}
}
public function authenticate_subdomain($attribute,$params)
{
Yii::app()->session['heretoo']=1;
if(!$this->hasErrors())
{
$this->addError('sub_domain','wow error');
}
}
Here is a look at the call to my form widget in my view
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'start-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
'afterValidate' => 'js:function(form, data, hasError) {
if(hasError) {
for(var i in data) {
$("#"+i).addClass("error_input");
}
$("#error_div").show();
$(window).scrollTop($("#error_div").position());
return false;
}
else {
form.children().removeClass("error_input");
$("#error_div").hide();
return true;
}
}',
'afterValidateAttribute' => 'js:function(form, attribute, data, hasError) {
if(hasError)
{
$("#"+attribute.id).addClass("error_input");
} else {
$("#"+attribute.id).removeClass("error_input");
}
}'
),
'htmlOptions'=>array(
'class'=>'reg-page',
),
)); ?>
All of the other validation rules will create the appropriate errors, but the custom validation functions are not even being ran. I can tell because they are not adding the variables “here” and “heretoo” to the session. I also put a die() call in both just to confirm the functions were not being called. I looked at the built in LoginForm.php for inspiration but I can’t see any significant difference to my setup. I hope there is something obvious to you all that I am missing.