1

更新

从 OhGodWhy 的评论中尝试新代码。当我使用此代码单击提交时,没有任何反应:

        <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>

原始问题

我正在尝试提交一个包含 3 个文本字段、一个富文本字段和一个文件上传的表单。我已经成功地在另一个表单上使用了 jQuery 验证,并且效果很好。但是,当我更新此表单的代码时,它不会提交已上传的富文本数据或文件。放入姓名、电子邮件和电话字段的信息会进入数据库,但最后两个(富文本和文件选择)没有,相应的电子邮件也不会发送。提交表单后,如果一切不正常,我会看到我写的消息。

我对 PHP 很陌生,不知道如何解决这个问题。我对jQuery的理解也有限。我尝试按照此处的步骤操作,但屏幕上除了我输入的消息外没有看到任何内容。当我查看 FF 或 Chrome 中的开发人员工具时,我在控制台中看不到任何错误消息。如果我删除 jQuery 验证脚本一切正常。

任何人都可以帮助我吗?这是js我的表单页面上的:

<script type="text/javascript" src="../assets/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
<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) {
    $.post('../scripts/process-application.php', $("#jobapp").serialize(), function(data) {
     $('#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."; 
 } 
 ?>

我知道这是很多代码,不知道有什么更好的方式来展示你。感谢您对此的关注。

4

0 回答 0