marcoc
(marcoc)
1
hi all i’m a noob of this framework and i want to lean how to pass value from a form to another
in the start_1 form i have this code
<?= Html::label('Color', 'modl', ['class' => 'control-label']) ?>
<?= Html::textInput("Color", $value, ['id' => 'color', 'class' => 'form-control']) ?>
<?= Html::submitButton('Go',['Start_2'], ['class' => 'btn btn-success']) ?>
in the controller i have created this action
public function actionStart_2( ){
$cl=$_POST["color"];
return $this->render('start_2',"cl" => $cl]);
when i render start_2 $cl is always empty?
any solution or simple idea?
tks all
softark
(Softark)
2
Hi @marcoc,
Your textInput here has a name of Color
and a value of $value
. So you have to write your controller accordingly.
$cl = $_POST["Color"];
return $this->render('start_2', "value" => $cl]);
But usually we don’t do it like this. We use a Model to pass values between the view and the controller.
Please check the following section of the guide.
Guide > Getting Started > Working with Forms
1 Like
marcoc
(marcoc)
3
hi tks but its not work
i get this error
Undefined index: Color
i have this in start_1
<?= Html::textInput(“Color”, $value3, [‘id’ => ‘color’, ‘class’ => ‘form-control’]) ?>
and this in the controller
$v1=$_POST[“Color”];
tks for the help
softark
(Softark)
4
Sorry, the code has an error.
return $this->render('start_2', ["value" => $cl]);
But, what error do you get?
marcoc
(marcoc)
5
hi i get this error
PHP Notice – yii\base\ErrorException
Undefined index: Color
i have this in start_1
<?= Html::textInput("Color", $Color, ['id' => 'color', 'class' => 'form-control']) ?>
and this in the controller
$v1=$_POST[“Color”];
tks for the help
softark
(Softark)
6
Can you show us the whole code of your actionStart_2()
method?
Probably you are trying to access $_POST
when it is not available.
But, IMO, you should read the guide before you try to write on your own.
marcoc
(marcoc)
7
here the code
function actionStart_2($bc,$md,$cl,$ts,$mg ){
if(isset($bc) and strlen($bc)>1){
$rmd='';
$rcl='';
$rts='';
$query=new \yii\db\Query();
$query->select(['Modello','Colore','Tessuto'])
->from('articoli')
->where(['IDArticolo'=>$bc]);
$rows=$query->all();
$command=$query->createCommand();
$rows= $command->queryAll();
return $this->render('dett', ["mg"=>$mg,"rows"=>$rows]);
}
else
{
$rmd='';
$rcl='';
$rts='';
$query=new \yii\db\Query();
$query->select(['Modello','Colore','Tessuto'])
->from('articoli')
->distinct()
->andFilterWhere(['like','Modello',$md])
->andFilterWhere(['like','Colore',$cl]);
//->orFilterWhere(['like','Tessuto',$ts]);
$rows=$query->all();
$command=$query->createCommand();
$rows= $command->queryAll();
return $this->render('start_2', ["rows"=>$rows,"mg"=>$mg]);
}
if i use java to read the value of the fields i can passing the value but if i use post the data is always empty
Tks for your time