Yii2 表单提交按钮必须单击两次才能操作.如何防止这种情况? [英] Yii2 form submit button must be clicked two times for action. How to prevent this?

查看:37
本文介绍了Yii2 表单提交按钮必须单击两次才能操作.如何防止这种情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

yii2提交按钮需要在表单中点击两次

yii2 submit button needs to be clicked two times in form

我遇到了一个问题,我需要检查控制器中的多个提交按钮.它有效,但我需要单击提交按钮两次.在控制器中:

I have a problem where I need to check more than one submit buttons in the controller. It works but I need to click submit buttons two times. In controller :

switch(\Yii::$app->request->post('submit')) {
                case 'submit_1' :

                  //my code 
                   break;  

                case 'submit_2' :                   
                 //my code 

在视图中

<?= Html::submitButton('NEXT', ['name' => 'submit', 'value' => 'submit_2','class'=>'btn btn-primary pull-right']) ?>
<?= Html::submitButton('PREVIOUS', ['name' => 'submit', 'value' => 'submit_3','id'=>'next_summary', 'class' => 'btn btn-primary pull-right']) ?>

推荐答案

使用 jquery 保留字作为属性 ID 或属性名称存在问题.

There is an issue with using jquery reserved words as your attribute id or attribute names.

在以下位置搜索命名提交按钮等表单元素时要小心"https://github.com/yiisoft/yii2/blob/master/docs/guide/input-forms.md

Search for "Be careful when naming form elements such as submit buttons" at https://github.com/yiisoft/yii2/blob/master/docs/guide/input-forms.md

https://api.jquery.com/submit/

更改您的提交名称将解决您的点击两次问题:

Changing your submit names will fix your click twice problem:

<?= Html::submitButton('NEXT', ['name' => 'submit_next', 'value' => 'submit_2','class'=>'btn btn-primary pull-right']) ?>
<?= Html::submitButton('PREVIOUS', ['name' => 'submit_prev', 'value' => 'submit_3','id'=>'next_summary', 'class' => 'btn btn-primary pull-right']) ?>

这篇关于Yii2 表单提交按钮必须单击两次才能操作.如何防止这种情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆