Answer the question
In order to leave comments, you need to log in
Yii2 ActiveForm not accepting values from model?
Hello!
Straight to the point. The task is trivial to impossibility. We write a feedback form (in the form of a questionnaire), wrote them more than once and everything was ok. The model itself is NOT connected to the database, and immediately after validation sends a letter to the mail.
namespace frontend\models;
use yii\base\Model;
class QuestionaryForm extends Model
{
//.. для краткости пишу не все поля
public $organization;
public $position;
public $username;
public function scenarios()
{
//...тут все как обычно
}
//... тут правила валидации
public function rules(){}
}
<article>
<? $form = \yii\widgets\ActiveForm::begin() ?>
<?= $form->field($model, 'organization')?>
<?= $form->field($model, 'position')?>
<?= $form->field($model, 'username')?>
<?= \yii\helpers\Html::submitButton("Отправить", ['class' => 'btn btn-w-svg']) ?>
<? \yii\widgets\ActiveForm::end();?>
</article>
public function actionFeedback()
{
$model = new QuestionaryForm();
$model->scenario = 'default';
//... здесь действия после отправки формы
return $this->render('questionary', ['model' => $model]);
}
<article>
<? $form = \yii\widgets\ActiveForm::begin() ?>
<?= \yii\helpers\Html::submitButton("Отправить", ['class' => 'btn btn-w-svg']) ?>
<? \yii\widgets\ActiveForm::end();?>
</article>
Answer the question
In order to leave comments, you need to log in
Good afternoon.
About loading styles, scripts. You have in the template, in the head
Take the feedback form, which is set by default when you install yii2 itself, check it out.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question