Hello
I have an issue about displaying error in a yii form.
This is my controller:
$custom_user->attributes = $_POST['CustomUser'];
if($custom_user->validate())
{
...
save
...
}
else
{
$custom_user->addError('username', 'Error X');
$this->render('index',
array('user'=>$custom_user,
'tab'=>$tab_person,
));
}
This is my index view:
<?php $form=$this->beginWidget('BaseForm', array(
'id'=>'user-form',
'action'=>Yii::app()->createUrl('person/createUser'))); ?>
<?php echo $form->errorSummary($user);?>
<div class="right">
<?php echo $form->textField($user,'username',array('size'=>30,'maxlength'=>255)); ?>
<br/><?php echo $form->error($user,'username'); ?>
</div>
...
...
<div style="float: left;">
<?php echo $form->dateField($user,'valid_from',null,'valid_from_formated'); ?>
<br/><?php echo $form->error($user,'valid_from'); ?>
</div>
Here is my BaseForm
public $enableClientValidation = true;
public $enableAjaxValidation = true;
public $clientOptions = array( 'hideErrorMessage'=>false,
'validateOnSubmit'=>true,
'validateOnChange'=>false,
'validateOnType'=>false,
'afterValidateAttribute' => 'js:enableSubmitAV',
'afterValidate' => 'js:submitFormAV');
Here is the problem:
$form->errorSummary($user);
is empty and noting is display under
$form->error($user,'username');
But if I look in Firebug I can see that under "response" tab:
{"CustomUser_valid_until":["Valid Until must be greater than \"20121127\"."]}
it’s a good thing because it means my rules work great. But none errors are displayed. Not this one and even the error “Error X” I add in my controller is not diplayed… (I’m sure I pass throught the else statement, i tried it).
So, does anyone could have an idea? (What I need is display my form error)
Thanks for reading me and sorry for my approximate English.
Have a good day
Michaël