Form with two submit buttons

I have a form with two submit buttons like this:

<form id="starterWizard__form" class="starterWizard__form" action="/wizard/step1?id=19623" method="post"></form>
<!-- my form fields -->
<input type="submit" class="btn btn-primary" name="Events[submitbutton]" value="Save and Exit" form="starterWizard__form">
<input type="submit" class="btn btn-primary" name="Events[submitbutton]" value="Continue" form="starterWizard__form">

In my controller I want to implement different logic based on which submit button is used to post the form. But the problem is that I don’t see “submitbutton” in $_POST. Any idea why this doesn’t work in Yii framework? If I test it in a plain php file without Yii then it works.

I have tried generating markup for submit buttons using both ActiveField and Yii Helpers and neither works. Below is my Yii code for submit buttons:

$form->field($model, 'submitbutton', [
		'template' => '{input}',
		'inputOptions' => [
			'form' => 'starterWizard__form',
			'type' => 'submit',
			'value' => 'Save',
			'class' => 'btn btn-primary'

Html::submitInput('Continue >>', [
	'class' => 'btn btn-primary',
	'form' => 'starterWizard__form',
	'name' => 'Events[submitbutton]',
	'value' => 'continue'
1 Like

This issue seems to be due to javascript that Yii runs in the page. If I comment out the following line of script in the page, then problem gets resolved.

jQuery('#starterWizard__form').yiiActiveForm([], []);

It feels like a bug in yii.activeForm.js.

I have reported this on github as well:

Using ActiveForm with its ActiveFields activates client side validation by default. You sure the form got really submitted?

How did you have defined your “submitbutton” in your Model class?
Is it an attribute/a property or a member var?

@Androphin That’s not true, ActiveForm has an option for disabling client side validation, see this:$enableClientValidation-detail
The problem was due to a bug in ActiveForm JavaScript which you can learn more about here:

@smohadjer Sure it is. You linked to it yourself. It’s activated by default.
On github, alex-code mentioned it too.
Are you sure you fully understand the process?

Yes, I already resolved this issue using feedback I got on github issue that I had opened. All I had to do was to set “enableClientScript” to false, so I’m not affected by the bug in ActiveForm JavaScript. When no javascript is loaded, the form works flawlessly with two submit buttons even when they sit outside the form.