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