Hello guys,
I’m trying to make unique mobile number on registration.
So, I’m using Ajax validation. But I got blank page when I click on button save.
Can you help me
Model:
public function rules()
{
return [
[['clicnic_idclicnic'], 'required'],
[['clicnic_idclicnic','day','month','year'], 'integer'],
[['birthday', 'first_login_date', 'last_login_date'], 'safe'],
[['first_name', 'last_name', 'street', 'plc', 'city', 'phone', 'mobile', 'email'], 'string', 'max' => 45],
[['mobile'],'unique'],
];
}
View
<?php $form = ActiveForm::begin([
'enableAjaxValidation'=>true,
]); ?>
…
<?= $form->field($model, ‘mobile’)->textInput([‘maxlength’ => true]) ?>
Controller
public function actionCreate()
{
$model = new Patient();
if(Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())){
Yii::$app->response->format = 'json';
return ActiveForm::validate($model);
}
$year[] = null;
for ($i=1950; $i <= date("Y"); $i++) {
$year[$i] = $i;
}
$day[] = null;
for ($i=1; $i <= 31; $i++) {
$day[$i] = $i;
}
$month[] = null;
for ($i=1; $i <= 12; $i++) {
$month[$i] = $i;
}
if ($model->load(Yii::$app->request->post()) ) {
$model->birthday = $model->year.'-'.$model->month.'-'.$model->day;
if ($model->save()) {
return $this->redirect(['appointment/index','phonenum'=>$model->mobile]);
}
} else {
return $this->render('create', [
'model' => $model,
'clinic' => Clinic::find()->all(),
'day' => $day,
'month' => $month,
'year' => $year,
]);
}
}