yii2 Date validation is not working -
in model have start , end date , need compare start , end dates.i added validation rules format , custom validation rules compare
[['start_date','end_date'], 'date', 'format' => 'yyyy-m-d'], ['start_date','validatedates'], public function validatedates(){ if(strtotime($this->end_date) <= strtotime($this->start_date)){ $this->adderror('start_date','please give correct start , end dates'); $this->adderror('end_date','please give correct start , end dates'); } }
i tried format validation
[['start_date','end_date'], 'date', 'format' => 'php:y-m-d'],
in view file customized start , end date design
<?= $form->field($quote, 'start_date',['template' => '{label}{input}<p class="help-block help-block-error">{hint}</p><div class="dtbox"></div>'])->textinput(['data-field' => 'date'])->label("arrival date", [ 'class' => 'control-label quote-layout-text', ]); ?> <?= $form->field($quote, 'end_date',['template' => '{label}{input}<p class="help-block help-block-error">{hint}</p><div class="dtbox"></div>'])->textinput(['data-field' => 'date'])->label("departure date", [ 'class' => 'control-label quote-layout-text', ]); ?>
i added start , end date validation required validation messages required fields.but didn't validation messages format , compare.
it seems don't have {error}
tag in fields template. try add it.
Comments
Post a Comment