loveorigami / yii2-modal-ajax

A wrapper around Yii2 Bootstrap Modal for using an ActiveForm via AJAX inside.
MIT License
50 stars 30 forks source link

Empty model saved #5

Closed Zhassulan closed 6 years ago

Zhassulan commented 6 years ago

Hello! Why my model is empty saved?

loveorigami commented 6 years ago

Please, code

Zhassulan commented 6 years ago

form:

field($model, 'username')->textInput(['maxlength' => true]) ?> field($model, 'name')->textInput(['maxlength' => true]) ?> field($model, 'lastname')->textInput(['maxlength' => true]) ?> field($model, 'email')->textInput(['maxlength' => true]) ?> field($model, 'status')->textInput(['maxlength' => true]) ?>
'btn btn-success']) ?>

action:

public function actionCreate() { $model = new Users (); if ($model->load ( Yii::$app->request->post () )) { if ($model->save ()) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['success' => true]; } return $this->redirect ( [ 'view', 'id' => $model->id] ); } } if (Yii::$app->request->isAjax) { return $this->renderAjax ( 'create', [ 'model' => $model ] ); } else return $this->render ( 'create', [ 'model' => $model ] ); }

index:

title) ?>

render('_search', ['model' => $searchModel]); ?> 'createUser', 'header' => 'New User', 'toggleButton' => [ 'label' => 'New User', 'class' => 'btn btn-primary pull-right' ], 'url' => Url::to(['/users/create']), // Ajax view with form to load 'ajaxSubmit' => true, // Submit the contained form as ajax, true by default 'options' => ['class' => 'header-primary'], 'autoClose' => true, ]); ?> 'grid-users', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'id', 'username', 'name', 'lastname', 'email:email', //'status', //'created_at', ['class' => 'yii\grid\ActionColumn'], ], ]); ?>
loveorigami commented 6 years ago

Where $model->validate()?

Zhassulan commented 6 years ago

Thanx!