Answer the question
In order to leave comments, you need to log in
How to include file and pass model to Yii2?
Hello everyone, I've run into this problem. Making a callback function
I have a model (Callback), a controller (CallbackController) and a view (frontend/view/callback/index.php).
Controller:
public function actionIndex()
{
$model = new Callback();
if ($this->request->isPost) {
if ($model->load($this->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', 'Сообщение успешно отправлено!');
return $this->redirect(Yii::$app->request->referrer);
}
}
return $this->render('index', compact('model'));
}
<?php echo $this->renderA('@frontend/views/callback/index.php'); ?>
<?php \yii\widgets\Pjax::begin(); ?>
<?php $form = \yii\bootstrap\ActiveForm::begin(['id' => 'callback-form-index', 'action' => ['callback/index'],]); ?>
<div class="modal-body">
<?= $form->field($model, 'name')->textInput(['maxlength' => true, 'placeholder' => 'Ваше имя']) ?>
<?= $form->field($model, 'phone')->textInput() ?>
<?= $form->field($model, 'reCaptcha')->widget(
\himiklab\yii2\recaptcha\ReCaptcha2::class,
[
'siteKey' => 'мой ключ, // unnecessary is reCaptcha component was set up
]
) ?>
</div>
<div class="modal-footer">
<?= \yii\helpers\Html::submitButton('Заказать обратный звонок', ['class' => 'callback_btn', 'name' => 'callback-button', 'id' => 'refreshButton1', 'onclick' => "yaCounter51997982.reachGoal('buttonCallback'); return true;"]) ?>
</div>
<?php \yii\bootstrap\ActiveForm::end(); ?>
<?php \yii\widgets\Pjax::end(); ?>
Call to a member function isAttributeRequired() on null
Answer the question
In order to leave comments, you need to log in
<?php echo $this->renderPartial('@frontend/views/callback/index.php',["model" =>new Callback()]); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question