Hi,
i use an CActiveForm with Ajax-validation.
During an Validation, 2 things are being validated:
1.) is an URL an URL and (using build in CUrlValidator)
2.) is the time since the last user action more than 30 seconds? (using own validation)
This is the code for the validation rule, where Z is the attribute for the URL:
return array(
array('Z','url','defaultScheme'=>'http','allowEmpty'=>false,'on'=>'create'),
array('Z','length', 'max' => 1000, 'on'=>'create'),
array('E','checkLastActive','secondsToWait'=>30,'on'=>'create'),
);
Both validation-rules works ($model->validate() returns false in some cases), but only the URL validator returns an error message, if the URL is not correct.
The custom validator does not have an error message, even if i define one on addError:
public function checkLastActive ($attribute,$params)
{
$valid=[....code to check if it is valid...]
if (!$valid)
{$this->addError($attribute, 'Only one update in '.$params['secondsToWait'].' seconds.');}
}
During debugging i can see, that the if statement works fine.
On controller side, i try to get the error message with the following code:
if (isset($_POST['ajax']))
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
The output for an Attribute ‘E’ which is not valid is:
{"map_E":[null]}
(where map is the model and E the attribute).
The output for an non-valid URL is like that: {"map_Z":["Z is not a valid URL."]} (works like aspect)
I’m searching for hours, but can’t find the error?!
Thank you for any kind of help.
rall0r