I am using Yii Framework 2.0. I have a form with a text input field which is meant for a date. I have read the Yii Framework 2.0 about the Class yii\\validators\\Validat
Working solution. My rules() method:
public function rules()
{
return [
[['inputfield_date'], 'required'],
[['inputfield_date'], 'safe'],
['inputfield_date', 'date', 'format' => 'yyyy-M-d H:m:s'],
];
}
My form in the view page:
= $form->field($model, 'inputfield_date')->textInput(); ?>
My method in controller:
if ($model->load(Yii::$app->request->post()) && $model->validate()):
if($model->save()):
// some other code here.....
endif;
endif;
Note that the date format depends on how you define your date format input field. Note once again that this is not an AJAX validator. After clicking on the submit button, you will see the error message if you enter something else which is not a date.