Passing aditional parameters to controller

Hello, in Yii 1 I could ADD aditional parameters in a form submit to send them to a controller processing. For example, if I wanted to know if the user clicked in a "Add" link in the form, I did this:


<?php echo CHtml::link('Add', '#', array('submit'=>'', 'params'=>array('MyParam1'=>'100', 'MyParam2'=>true)));?>

So in the controller I could evaluate the values of those aditional parameters and take appropiate action. The previous code, resulted in this:


<a href="#" id="yt0">Add</a>


<script type="text/javascript">

/*<![CDATA[*/

jQuery(function($) {

jQuery('body').undelegate('#yt0','click').delegate('#yt0','click',function(){jQuery.yii.submitForm(this,'',{'MyParam1':'100','MyParam2':true});return false;});

});

/*]]>*/

</script>

However in Yii 2, the following code:


<?= Html::a('Add', '#', [

    'data'=>[

        'method' => 'post',

        'params'=>['MyParam1'=>'100', 'MyParam2'=>true],

    ]

]) ?>

Produces this:


<a href="#" data-method="post" data-params="{'MyParam1':'100','MyParam2':true}">Add</a>

The problem is that the link in this example in Yii 2, only sends the parameters specified in the link code, ignoring the rest of the form control values (post parameters).

Any ideas on how to accomplish this in Yii 2? Thank you!

your requirement is u want to submit form with parameter.

see below

<?php $form = ActiveForm::begin([ ‘options’ => [‘enctype’=>‘multipart/form-data’],

        'id' =&gt; 'my-form-category',


        'action' =&gt; 'updateadditional?id='.&#036;_GET['id'],

// ‘beforeSubmit’ => ‘submitForm’,

 'type' =&gt; ActiveForm::TYPE_VERTICAL,'formConfig' =&gt; ['showErrors' =&gt; true],      


]); ?&gt;

public function actionUpdateadditional($id)

{   


         &#036;id =  &#036;id;// parameter.


       &#036;data = Yii::&#036;app-&gt;request-&gt;post();


     // u will get post data here. with get id.


}

Thank you rups g. One of the problem was that the link was outside the “fieldset” tags used in the form, so it was alone. However, after correctly placing the link, the behavior is still incorrect, and is actually the following that has been already reported: Issue #8015 It seems that it’s set to be fixed on 2.0.5 release, so I guess we’ll have to wait…

okay.

many thank to share information.