【发布时间】: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