3

Here is my rules method:

public function rules() { 
  $newRules = array( 
    array('password_verification, valid_from, valid_until', 'required'),                
    array('password_verification', 'length', 'min'=>6, 'max'=>32), 
    array('password_verification', 'compare', 'compareAttribute'=>'password'), 
    array('username, email', 'length', 'min'=>3,'max'=>255),
    array('password', 'length','min'=>6, 'max'=>32), array('username, email', 'unique'), 
    array('email', 'email'), array('id, type, username, password, email, valid_from, valid_until', 'safe'), 
  ); 
  return array_merge($newRules,parent::rules()); 
}

And here is my view (fields which give a hard time):

<div class="row">
  <?php echo $form->labelEx($user,'password_verification',array('label'=>'Verification mot de passe','class'=>'forsys-label')); ?>
  <?php echo $form->passwordField($user,'password_verification',array('size'=>30,'maxlength'=>32)); ?>
  <?php echo $form->error($user,'password_verification') ?>
</div>

<div class="row">
   <?php echo $form->labelEx($user,'valid_from',array('label'=>'Valide depuis le','class'=>'forsys-label')); ?>
   <?php echo $form->dateField($user,'valid_from'); ?>
   <?php echo $form->error($user,'valid_from'); ?>
</div>
<div class="row">
   <?php echo $form->labelEx($user,'valid_until',array('label'=>"Valide jusqu'au",'class'=>'forsys-label')); ?>
   <?php echo $form->dateField($user,'valid_until'); ?>
   <?php echo $form->error($user,'valid_until'); ?>
</div>

Some informations:

  • enableClientValidation and enableAjaxValidation are both at true
  • datefield is a costum method. It's not where the problem come from (a colleague use it in the same way I use it without this problem).

My Problem:

For "valid_until" and "valid_from" errors are not displayed on the HTML. If I let "password_verification" empty, when I change the focus an error appears (because of ajaxValidation onChange), but none errors if I let "valid_until" or "valid_from" empty.

But these errors are noticed by Yii, I can see them in firebug if I check the ajax request response.

So if all fields are empty, nothing will be created in DB because of 3 errors, but only one (password_validation) will be displayed.

If any body have an idea, you're welcome :)

Sorry for my approximate english

Thank you for read me, have a good day.

Michaël

Stephan Muller
  • 27,018
  • 16
  • 85
  • 126
Michaël
  • 1,120
  • 1
  • 15
  • 30
  • I would suggest that you check the name that your custom method `dateField()` applies to the generated input field. If your model name is User, then the field name should be `User[valid_from]` and `User[valid_until]`. This would let the AR class carry out the validation using `$this->valid_from` and `$this->valid_until` – Oladapo Omonayajo Dec 19 '12 at 11:18

1 Answers1

0

You have these attributes marked as "safe" in the last rule. Probably that's the reason. Remove that rule or add a scenario for it (usually attributes are declared as safe on 'search' scenario - e.g. add 'on'=>'search' element to that rule).

Anton Sergeyev
  • 929
  • 1
  • 9
  • 24