[*]Correct here ([font="Courier New"]$this->attribute[/font] instead of [font="Courier New"]$this->[color="#FF0000"]$[/color]attribute[/font]) :
if($this->$attribute=="Yes")
[*]You should escape the single quote inside your string like this
$this->addError('BirthDayDate', 'Can\'t say Happy Birthday');
or of course, double-quote your string, and leave your single quote as it is
[*]If it’s not enough, remove all the ifs in your validation function, and see if it works. If it’s the case, check back what you’d have removed for errors
[*]If nothing works, please post your model and form
I told you in my first post [font="Courier New"]$this->attribute[/font], I guess that was wrong. Please add the last line in the code below, and also try the alternate syntax [font="Courier New"]$this[$attribute][/font] instead of [font="Courier New"]$this->$attribute[/font]
public function bValidator($attribute,$params)
{
if($this[$attribute]=="Yes") // alternate syntax if $this->$attribute doesn't work
{
$this->addError('bdate','BirthDay');
}
return false; // that's important
}
Hmmm I’ve just downloaded the codes you’ve put (I’d have preferred inline code
You have to make these changes:
_form.php
…
<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'bdate',
'name'=>'Test[bdate]', //addError('bdate',…) looks for a field named "Test[bdate]"
…
Test.php
…
public function bValidator($attribute,$params)
{
if($this[$attribute]=="Yes")
{
$this->addError('bdate','BirthDay');
}
return false;
}
…
Edit: You may want also try with normal input field instead of CJuiDatePicker. In that case, you don’t have to make that kind of change in _form.php, but you need the change(s) in your model anyway (see also my last post).
Yes the same thing (clear/add more than a single attribute’s messages on ajax validation). But I give an image so member can understand what I need. Thanks!