【问题标题】:Double confirmation box in Symfony 2Symfony 2 中的双重确认框
【发布时间】:2016-06-01 19:00:25
【问题描述】:

我在 Symfony 中有一个包含表单的视图。在提交表单之前,我在 jQuery 中有一个确认框。提交表单后,在控制器函数中,我检查数据库中表单的值,然后在执行操作之前显示另一个确认框,具体取决于表单的值。

我的问题是如何在我的示例中显示第二个确认框

这是我的看法:

<div>
    <form id="regexpForm" action="" method="post">
        <input type="hidden" name="action" value="test" />
        <ul>
            <li class="clear mandatory">
                <input type="submit" class="button" value="submit" />
            </li>
        </ul>
    </form>
    <div id="dialog" title="Confirmation"></div>
</div>
<script>
    jQuery( document ).ready(function( $ ) {
        var userConfirmed = false;
        $("#regexpForm").validate({
            submitHandler: function(form) {
                $("#dialog").dialog({
                    open: function () {
                        var markup = 'Confirmation';
                        $(this).html(markup);
                    },
                     buttons: {
                         "Ok": function() {
                             form.submit();
                             $(this).dialog("close");
                         },
                         "Cancel": function() {
                             $(this).dialog("close");
                         }
                     }
                });
            }
        });
    });
</script>

我的控制器中的功能:

public function testAction()
{
    //Verification of $this->get('request')->get('action') in DB
    if($this->get('request')->get('action'))
    {
        // Display a confirmation box and if ok execute action 1
    }
    else
    {
        // Display a confirmation box and if ok execute action 2
    }
}

提前谢谢你

【问题讨论】:

  • 我不明白为什么用户要确认两次。如果您需要根据某些情况更改表单,您可以看到here
  • 第一次确认是输入数据的格式(使用正则表达式),第二次是在检查数据库之后
  • 只是一个评论:如果你背着 Symfony 的力量,你应该使用表单组件而不是手写表单

标签: javascript php jquery symfony


【解决方案1】:

您需要对您的testAction 进行ajax 调用。如果预期值没问题,你会返回一个这样的标志。然后你在你的 javascript 中捕获这个标志。如果标志是true,则会显示另一个确认框。 然后,当用户验证第二个确认框时,您将再次调用您想要的 controller 中的任何 action,这将执行操作 1 或 2。 关键是,这是一个两步过程。

【讨论】:

    猜你喜欢
    • 2012-01-03
    • 2014-07-26
    • 2015-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多