Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use yiihelpersHtml;
- use yiiwidgetsActiveForm;
- $form = ActiveForm::begin([
- 'id' => 'form1',
- ]) ?>
- <?= $form->field($postForm, 'title') ?>
- <?= $form->field($postForm, 'text') ?>
- <?= $form->field($postForm, 'userId') ?>
- <div class="form-group">
- <?= Html::submitButton('Добавить', ['class' => 'btn btn-primary']) ?>
- </div>
- <?php ActiveForm::end() ?>
- public function actionAdd()
- {
- $postForm = new Post();
- if (Yii::$app->request->isAjax) {
- $post = new Post();
- $post->title = Yii::$app->request->post('title');
- $post->text = Yii::$app->request->post('text');
- $post->userId = Yii::$app->request->post('userId');
- $post->save();
- if (!$post->save()) {
- print_r($post->errors);
- }
- }
- return $this->render('addPost', compact('postForm'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement