how to check a submit button value in controller (Yii2). I am working with multiple submit button.
I tried simple php code. but it is not working.
if(isset($_POST['next']) && $_POST['next']=='gotocartfive')
code in view is :
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'status')->checkbox(); ?>
</div>
<div class="form-group">
<?php echo Html::submitButton('NEXT',array('value'=>'gotocartfive','name' => 'next','id'=>'next_summary','class'=>'btn btn-primary pull-right')); ?>
<?php echo Html::submitButton('PREVIOUS',array('value'=>'previous_four','name' => 'cartfour','class'=>'btn btn-primary pull-left')); ?>
</div>
<?php ActiveForm::end(); ?>
You can try following code.
Code in view file.
Code in controller action
Please let me know if you've any questions.
Also you can add this little js snippet to your project and bind it to beforeSubmit event in yii.activeForm.js like this:
This code removes all hidden inputs which are being created by yii.activeForm before submitting. Then after this inputs will be recreated by yii.activeForm.
hope this helps
Try This :
View File
Controller File
PHP
When you submit form by pressing enter (without click any submit button), submit_1 will be default value.