【发布时间】:2016-07-23 11:51:15
【问题描述】:
表单提交按钮,我必须使用 jquery 检查一些验证。但是我也使用了带有 form_open(xxxx) 的 codeiginiter 验证,这使得我的提交按钮 jQuery 没有被调用。我该怎么做才能使这两项工作?之前还是之后? (我要前后端检查)
<?php $prevURLPATH=urlencode($p); echo form_open('form/'.$usr.'/'.$name.'?prevURL='.$p); ?>
<div class="form-group row">
<label class="col-md-3 control-label text-center"></label>
<div class="col-md-8">
<button id="submit-upload-form" class="btn btn-primary btn-tw" onclick="setup(); return false;"><i class="glyphicon glyphicon-upload"></i>Submit</button>
<button id="validate" hidden="true" type="submit"></button>
</div>
</div>
function setup()
{ .......Checking some fields in the form...............}
我想要的是: 在提交表单时,Jquery/JS 检查(前端),然后是后端 codeigniter 表单检查。
(似乎当用户单击提交按钮时,它会忽略所有 jquery 验证并直接进入 codeigniter 验证。我想如果我在 php 中使用 form_open() 我会非常有限,对吧?)
我正在关注这个link。
希望找到答案,以便其他人知道使用 codeiginiter 验证的正确方法。
感谢您迄今为止的所有回答,但我仍然找不到正确的解决方案。 :( 其他人请帮忙?
【问题讨论】:
-
在你的 jquery 函数中添加
event.preventDefault() -
您可以将任何功能绑定到单击按钮。这个按钮是否是提交无关紧要,绑定不会阻止提交的发生。我已经测试了我的答案并且它有效:它首先触发 jQuery 函数,然后触发表单验证。
标签: javascript php jquery codeigniter validation