添加jQuery验证后,Php表单将无法正确提交
更新 尝试OhGodWhy评论中的新代码。当我使用此代码单击submit时,不会发生任何事情:添加jQuery验证后,Php表单将无法正确提交,php,jquery,forms,validation,Php,Jquery,Forms,Validation,更新 尝试OhGodWhy评论中的新代码。当我使用此代码单击submit时,不会发生任何事情: <script type="text/javascript"> $(document).ready(function(){ $("#jobapp").validate({ debug: false, rules: { email: {
<script type="text/javascript">
$(document).ready(function(){
$("#jobapp").validate({
debug: false,
rules: {
email: {
required: true,
email: true
}
},
messages: {
email: "Please enter a valid email address.",
},
submitHandler: function(form) {
$.ajax('../scripts/process-application.php', new FormData($("#jobapp")[0]), function(data) {
processData: false;
$('#confirm').html(data);
$('#job-application').hide();
});
}
});
});
</script>
这是表单的HTML:
<div id="job-application">
<p><span>Position:</span> <?php echo $jobtitle;?></p>
<p><span>Job ID:</span> <?php echo $jobid;?></p>
<p class="req">All Fields are Required</p>
<form action="" method="post" enctype="multipart/form-data" name="jobapp" id="jobapp">
<input name="jobtitle" type="hidden" value="<?php echo $jobtitle;?>" />
<input name="jobid" type="hidden" value="<?php echo $jobid;?>" />
<label>Full Name</label><input name="name" type="text" id="name"/>
<label>Email</label><input name="email" type="text" id="email" size="35" />
<label>Phone</label><input name="phone" type="text" id="phone" size="35" />
<label>Cover Letter</label><textarea name="coverletter" id="coverletter"></textarea>
<script>
CKEDITOR.replace( 'coverletter' );
</script><br />
<label>Upload Resume:</label><input type="file" name="resume" />
<input name="Submit" type="submit" id="submit" value="Submit" class="button" />
<input name="clear" type="reset" value="Clear Form" class="button"/>
</form>
</div>
<div id="confirm"></div>
这是处理应用程序的php文件:
<link href="../assets/lcoastyles.css" media="all" type="text/css" rel="stylesheet" />
<?php require_once('lcoa.php'); ?>
<?php
//This is the directory where resumes will be saved
$target = "../careers/resumes/";
$target = $target . basename( $_FILES['resume']['name']);
$resume=($_FILES['resume']['name']);
//Writes the information to the database
$insertSQL = "INSERT INTO applicants (id, name, email, phone, jobid, jobtitle, coverletter, resume) VALUES ('','".$_POST['name']."','".$_POST['email']."','".$_POST['phone']."','".$_POST['jobid']."','".$_POST['jobtitle']."','".$_POST['coverletter']."','".$resume."')";
mysql_select_db($database_lcoa, $lcoa);
$Result1 = mysql_query($insertSQL, $lcoa) or die(mysql_error());
//Writes the resume to the server
if(move_uploaded_file($_FILES['resume']['tmp_name'], $target))
{
//Sends Email
$sendto = "email@email.com";
$name = nl2br($_POST['name']);
$email = nl2br($_POST['email']);
$phone = nl2br($_POST['phone']);
$jobid = nl2br($_POST['jobid']);
$jobtitle = nl2br($_POST['jobtitle']);
$cover = nl2br($_POST['coverletter']);
$subject = "Submitted Job Application";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$headers = "From: " . strip_tags($email) . "\r\n";
$headers .= "Reply-To: ". strip_tags($email) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>Job Application Submitted</h2>\r\n";
$msg .= "<p><strong>Applied for:</strong> ".$jobtitle."</p>\r\n";
$msg .= "<a href='http://lcoawebservices.com/careers/resumes/".$resume."'>Download Resume</a>\r\n";
$msg .= "</body></html>";
if(@mail($sendto, $subject, $msg, $headers)) {
echo "";
} else {
echo "false";
}
//Tells you if its all ok
echo "<p>Thank you for submitting your application. Resumes submitted will be reviewed to determine qualifications that match our hiring needs.<br /><br /> If you are selected you will be contacted by a member of our recruiting team.</p><br /><br /><a href='../careers/job-postings.php'>Return to current opportunities</a>";
}
else {
//Gives and error if its not
ini_set('display_errors',1);
error_reporting(E_ALL);
echo "Sorry, there was a problem uploading your file. Please try again.<br /><br />If you continue to experience errors, please email lcoaweb@lecreuset.com.";
}
?>
我知道这是一大堆代码,不确定用什么更好的方式向您展示。谢谢您的关注。如果您否决了我的问题,请告诉我为什么,以便下次我能做得更好?谢谢。在Chrome和IE浏览器F12中打开一个控制台,然后再次尝试提交,查看控制台中是否有任何错误信息。可能通过控制台向您返回了一个错误。请将$jobapp.serialize替换为新FormData$jobapp[0];。在HTML5中,可以使用ajax将文件发送到服务器,但不能使用serialize。我也不确定这是否适用于IE10@BOMEz,我在控制台中没有收到任何错误消息。我将更新我的问题,让其他人也知道。将$.post更改为$.ajax,并将processData:false添加到您的ajax请求中。
<link href="../assets/lcoastyles.css" media="all" type="text/css" rel="stylesheet" />
<?php require_once('lcoa.php'); ?>
<?php
//This is the directory where resumes will be saved
$target = "../careers/resumes/";
$target = $target . basename( $_FILES['resume']['name']);
$resume=($_FILES['resume']['name']);
//Writes the information to the database
$insertSQL = "INSERT INTO applicants (id, name, email, phone, jobid, jobtitle, coverletter, resume) VALUES ('','".$_POST['name']."','".$_POST['email']."','".$_POST['phone']."','".$_POST['jobid']."','".$_POST['jobtitle']."','".$_POST['coverletter']."','".$resume."')";
mysql_select_db($database_lcoa, $lcoa);
$Result1 = mysql_query($insertSQL, $lcoa) or die(mysql_error());
//Writes the resume to the server
if(move_uploaded_file($_FILES['resume']['tmp_name'], $target))
{
//Sends Email
$sendto = "email@email.com";
$name = nl2br($_POST['name']);
$email = nl2br($_POST['email']);
$phone = nl2br($_POST['phone']);
$jobid = nl2br($_POST['jobid']);
$jobtitle = nl2br($_POST['jobtitle']);
$cover = nl2br($_POST['coverletter']);
$subject = "Submitted Job Application";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$headers = "From: " . strip_tags($email) . "\r\n";
$headers .= "Reply-To: ". strip_tags($email) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>Job Application Submitted</h2>\r\n";
$msg .= "<p><strong>Applied for:</strong> ".$jobtitle."</p>\r\n";
$msg .= "<a href='http://lcoawebservices.com/careers/resumes/".$resume."'>Download Resume</a>\r\n";
$msg .= "</body></html>";
if(@mail($sendto, $subject, $msg, $headers)) {
echo "";
} else {
echo "false";
}
//Tells you if its all ok
echo "<p>Thank you for submitting your application. Resumes submitted will be reviewed to determine qualifications that match our hiring needs.<br /><br /> If you are selected you will be contacted by a member of our recruiting team.</p><br /><br /><a href='../careers/job-postings.php'>Return to current opportunities</a>";
}
else {
//Gives and error if its not
ini_set('display_errors',1);
error_reporting(E_ALL);
echo "Sorry, there was a problem uploading your file. Please try again.<br /><br />If you continue to experience errors, please email lcoaweb@lecreuset.com.";
}
?>