yiisoft/yii2

ActiveRecord form with two submit buttons doesn't post name of submit button

開放

#17,808 建立於 2020年1月17日

 (11 則留言) (0 個反應) (0 位負責人)PHP (6,784 個分叉)batch import
JShelp wanted

倉庫指標

星標
 (14,302 顆星)
PR 合併指標
 (平均合併 2天 15小時) (30 天內合併 47 個 PR)

描述

I have an "ActiveRecord" model named "Events" and a view with two submit buttons like below (generated HTML code in browser):

<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. If I test it in a plain php file without Yii then it works. I have also noticed the 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([], []);

Note that my form doesn't use client-side validation ('enableClientValidation' => false) and I have tried to add submit buttons using both ActiveField and Yii Html::submitInput and neither works. Below is related part of my Yii view:

$form = ActiveForm::begin([
	'enableClientValidation' => false,
	'id' => 'starterWizard__form',
	'options' => [
		'class' => 'starterWizard__form'
	]
]);
ActiveForm::end();

$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'
]);

貢獻者指南