我使用代码将表单拆分为不同标签中的部分......
<?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>
标签工作正常,我可以传递数据......
来自的标签
但问题是在验证字段时......
这是正在执行的php文件代码..
<!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>
验证来源: http://anvweb.com/blog/server-side-form-validation-with-jquery-plugin-and-php/
验证在正常形式下没有标签工作正常......但不在标签中工作..问题是什么?提前谢谢......
答案 0 :(得分:1)
<强>小提琴:强>
<强> http://jsfiddle.net/ve6KS/3/ 强>
<强> HTML 强>
<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">
<input type="text" name="dd_number" id="dd_number" />
</div>
<input name="" type="submit" value="submit" />
</div>
</form>
<强> jquery的:强>
$(function() {
$("#tabs").tabs();
$('#my_form').validate({
ignore: [],
rules: {
"name": {"required": true, "minlength": 2, "maxlength": 30},
"dd_number": {"required": true, "maxlength": 20},
"textfield": {"required": true, "minlength": 2, "maxlength": 30}
}
});
});
答案 1 :(得分:0)
将ignore
来电中的validate
设置更改为您不使用的选择器。默认情况下ignore
有&#34;:隐藏&#34;,这就是隐藏标签中的组件未经过验证的原因(即无论价值是多少,它们都会通过) 。通过将忽略选择器更改为您永远不会使用的选择器(例如&#34; .jksfdhskhfbskeyh&#34;),您的字段将照常验证。