Answer the question
In order to leave comments, you need to log in
How to put data in ActiveForm in YII2?
I must say right away that I don’t understand very well, that’s why I’m asking)
How can I take user data (Name, Email, Address, Phone), and place it in ActiveForm so that the values \u200b\u200bare already filled in the form fields.
Can this be done at all ???)
The form looks like this
<?php $form = ActiveForm::begin()?>
<?= $form->field($order, 'name')?>
<?= $form->field($order, 'email')?>
<?= $form->field($order, 'phone')?>
<?= $form->field($order, 'address')?>
<?= Html::submitButton('Заказать', ['class' => 'btn btn-success'])?>
<?php ActiveForm::end()?>
Answer the question
In order to leave comments, you need to log in
Before the form, in the action or directly in the view:
But it is more correct to make a method in the model that fills with default data. And call it in the action, when creating an instance of the model. Only in the model it will be$this->name = 'Вася';
there is little information about what is happening))) somewhere in the controller ....
$order = $Order::find()->where(['id'=>5])->limit(1)->one();// можно короче $order = $Order::findOne(5);
if(is_null($order)){
return false;
}
return $this->render('update',[
'order'=>$order,
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question