K
K
Konstantin Spirin2020-12-21 15:37:27
Yii
Konstantin Spirin, 2020-12-21 15:37:27

How to save the value of a text field after submitting to a form in yii2 framework?

How to save the value of a text field after submitting to a form in yii2 framework?
In the field, enter the value -
5fe0944d125db809480188.png
After sending to the form, as usual, there is a void in the field
5fe094bc66a45112136590.png
How to do that after submitting the form, there is data left.
Code
file main.php

$form = ActiveForm::begin(); 
$form->field($model, 'price')->textInput(['value' => $model->price,'maxlength' => true])
ActiveForm::end();


public function actionIndex()
    {
    $model = new Product();

 if($model->price){
         $price = $model->price;
      
       $query = Product::find()->where(['price' => $price]);
       }

 return $this->render('index', compact('hits','pages','model'),[
            'dataProvider' => $dataProvider,]);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Lykasov, 2020-12-21
@lykasov-aleksandr

You need to upload the entered data in the form:$model->load(Yii::$app->request->post)

B
bashcode, 2020-01-01
@bashcode

You receive a product-model from the form.
Load it in the action into the model, search, etc.
But! You do not give back loaded, apparently.
I don't like the compact function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question