ActiveRecord form with two submit buttons doesn't post name of submit button
#17,808 opened on 2020/01/17
Repository metrics
- Stars
- (14,302 個のスター)
- PR merge metrics
- (平均マージ 2d 15h) (30d で 47 merged PRs)
説明
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'
]);