0
我想创建一个表单页面,使用php和ajax jquery进行验证。
我从网上下载http://malsup.com/jquery/form/
表单页面的jQuery的:PHP与Jquery:如何验证表单并转到下一页
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript">
function checkAll(){
var errmsg = ""
document.getElementById("errmsg").style.display = "none";
if(document.getElementById("txtbox1").value == ""){
errmsg += "Type your title<br/>";
}
if(document.getElementById("file1").value == ""){
errmsg += "Upload your picture<br/>";
}
if(errmsg != ""){
document.getElementById("errmsg").style.display = "block";
document.getElementById("errmsg").innerHTML = errmsg;
return false;
}
}
$(document).ready(function() {
var options = {
target: '#div2', //Div tag where content info will be loaded in
url:'uploadfile.php', //The php file that handles the file that is uploaded
beforeSubmit: checkAll,
success: function() {
//Here code can be included that needs to be performed if Ajax request was successful
}
};
$('#Form1').submit(function() {
$('#Form1').ajaxSubmit(options);
return false;
});
});
</script>
</head>
<body>
<span id="errmsg"></span>
<div id="div2"></div>
<form name="Form1" id="Form1" method="post" action="next.php" enctype="multipart/form-data">
Title <input type="text" name="txtbox1" id="txtbox1" />
Picture <input type="file" name="file1" id="file1" /><br/>
<input type="submit" value="Submit" />
</form>
</body>
</html>
Uploadfile.php:
<?php
if (((@$_FILES["file1"]["type"] == "image/gif") || (@$_FILES["file1"]["type"] == "image/png")
|| (@$_FILES["file1"]["type"] == "image/jpeg")
|| (@$_FILES["file1"]["type"] == "image/pjpeg"))
&& (@$_FILES["file1"]["size"] < 30720))
{
}
else{
echo "Check your file";
}
?>
我的问题:
我想每个表单组件,包括文件上传创建验证(文件类型和大小检查),完成表单后,用户将被重定向到next.php(请参阅表单操作)。
由于使用ajax jquery验证文件上传,操作更改为uploadfile.php,并且如果用户填写了表单,页面将无处可用。
请帮我解决这个问题。
tmuguet,谢谢你的回复。 – 2013-02-11 14:37:11