0
votes

I have a written a form with the built in functions of Yii which works great. The form can be submitted when the user selects any of the dropdown-fields. The data is posted with the GET-method and the values show up in the url as key in an array. The array has the same name as the model for the form.

ex. url/index.php?r=controller/action&Modelname[y-value]=1&Modelname[x-value]=2

The problem is that when I want to add a submit button that should submit some extra variables those variables are submitted the normal way, without being included in the model-array. This means that I can't change the parameters of the model but instead new values are sent. What I want is for the parameters defined in the button to be submitted into the model-array.

ex. url/index.php?r=controller/action&Modelname[y-value]=1&Modelname[x-value]=2&x-value=3

My code for the button is:

CHtml::submitButton('X-value',array('name'=>'x','params'=>array('x-value'=>3)));
1

1 Answers

0
votes

Can you not add the field to your form with the given attribute name? If you don't want the values to be visible to the user you could always add them as a hidden field in your form. For example;

echo $form->hiddenField($model,'x-value');

... assuming $model is your model and x-value is the model attribute. Although as you already seem to have a Modelname[x-value] in your submitted values, do you not already have a field for x-value in your form?