doufu7835 2014-04-24 18:17
浏览 52

PHP选项卡 - 表单验证

i use the code to split a form in to parts in different tabs...

   <?php
session_start();
require_once('./server_validation/lib.php');?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Tabs - Default functionality</title>

   <script src="./server_validation/jquery-1.4.2.js"></script>
<script src="./server_validation/jquery.validate.min.js"></script>
<script>
    $(document).ready(function(){
        $('#my_form').validate({
          'rules': <?php echo json_encode($validation_rules); ?>
        });
    });
</script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#tabs" ).tabs();
  });
  </script>
</head>
<body>
 <form name="my_form" id="my_form" method="post" action="d1.php" enctype='multipart/form-data'>
<div id="tabs">
  <ul>
    <li><a href="#tabs-1">Nunc tincidunt</a></li>
    <li><a href="#tabs-2">Proin dolor</a></li>
    <li><a href="#tabs-3">Aenean lacinia</a></li>
  </ul>
  <div id="tabs-1">
    <p> <input type="text" name="textfield" id="textfield" /></p>
  </div>
  <div id="tabs-2">
   <input type="text" name="name" id="name" />
  </div>
  <div id="tabs-3">

  </div>
  <input name="" type="submit" value="submit" />
</div>
 </form>

</body>
</html>

tabs are working fine ad i can pass the data...

tabs from source

http://jqueryui.com/tabs/

But the problem is while validating the fields...

This is the working executed php file code..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" href="css/style.css" type="text/css">
   <script src="./server_validation/jquery-1.4.2.js"></script>
<script src="./server_validation/jquery.validate.min.js"></script>
<script>
    $(document).ready(function(){
        $('#my_form').validate({
          'rules': {"name":{"required":true,"minlength":2,"maxlength":30},"dd_number":{"required":true,"maxlength":20},"textfield":{"required":true,"minlength":2,"maxlength":30}}        });
    });
</script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form name="my_form" id="my_form" method="post" action="reg.php" enctype='multipart/form-data'>
  <label for="name"></label>




  <input type="text" name="name" id="name" />
  <label for='textarea'></label>
  <input type="text" name="textfield" id="textfield" />
  <input name='Submit' type='submit' value='Submit' />


</form>

</body>
</html>

validation source: http://anvweb.com/blog/server-side-form-validation-with-jquery-plugin-and-php/

Validation works fine in normal forms without tab... but not working in tabs.. wast is the problem??? thanks in advance...

  • 写回答

2条回答 默认 最新

  • doutuohan6606 2014-04-24 18:41
    关注

    Change the ignore settings in your validate call to a selector you don't use. by default ignore has ":hidden", and that's the reason why the components in hidden tabs don't get validated (i.e. they will pass, whatever their value is). by changing the ignore selector to a selector you will never use (like, e.g. ".jksfdhskhfbskeyh"), your fields will be validated as usual.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能