J
J
Julia __2018-04-02 11:24:40
Yii
Julia __, 2018-04-02 11:24:40

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

2 answer(s)
M
Maxim Timofeev, 2018-04-02
@julia_____kuleshova

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 = 'Вася';

D
Denis, 2018-04-02
@sidni

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,
]);

UPD generally make the model using the standard GII functionality and then CRUD and then a lot will become clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question