Pass A Variable From Form To Controller


in the main.php link i have a link User Create, this link renders me to the user/_form page and i passed a variable from the link to the _form page.

in main.php

array('label'=>'Assignment', 'url'=>array('/assignment/create', 'Student_Number'=>$value)),

in _form.php

here i need to display the variable in a textfield and then save it in the database when the user click on the submit button

 $ststudent = $_GET['Student_Number'];




i called this variable in the controller by $_POST[‘Assignment’][‘studentID’]

when i submit, an error appears that there is undefined index: studentID

i tried except of chtml::textfield, $form->textfield($model,$ststudent), it gives me an error to

i tried to add hidden file and call it in the controller, it gives me the same result. undefined field.

i tried too to pass a variable through the submit button and then call it in the controller using $_GET, the result was, undefined index $_GET

try $_POST, the same result

any help please

Hi freshyiiuser

Try this solution:

<?php echo $form->textField($model,'studentID',array('value'=>$ststudent)); ?>

it works :) thank uu