【问题标题】:Jquery form plugin not submitting to process pageJquery表单插件未提交到流程页面
【发布时间】:2023-03-23 10:00:01
【问题描述】:

我有一个使用 Jquery 表单插件的基本联系表单。我无法使用插件提交它。仅当我将 php 包含添加到 process.php 时,它才会提交。

Javascript:

 $(document).ready(function() { 
     $("#contact").validate({
         submitHandler: function(form) {
             $(form).ajaxSubmit({
                 url:"process.php",
                 type:"post",
             });
         }
     });
 });

这是我的联系表格:

 <form id="contact" method="post" name="validation" action="contact.php" onsubmit="return validateForm();">
     <fieldset> 

         <label for="name">Name</label>
         <input type="text" name="name" placeholder="Full Name" title="Enter your name" class="required">

         <label for="email">E-mail</label>
         <input type="email" name="email" placeholder="yourname@domain.com" title="Enter your e-mail address" class="required email">

         <label for="phone">Phone</label>
         <input type="tel" name="phone" placeholder="ex. (555) 555-5555">

         <label for="message">Question/Comment</label>
         <textarea name="message"></textarea>

         <input type="submit" name="submitted" class="button" id="submit" value="Send Message"     />

     </fieldset>
 </form>

进程.php

   <?php
   function GetHeaders()
   {
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    // Additional headers
    $headers .= 'From: Company Name<info@companyname.com>' . "\r\n";
    return $headers;
   }
   // Get Data  
   $name = strip_tags($_POST['name']);
   $email = strip_tags($_POST['email']);
   $phone = strip_tags($_POST['phone']);
   $message = strip_tags($_POST['message']);
    // Send Message
    $headers = GetHeaders();
    $intro = "\"Thank you for contacting Company Name. We are very interested in assessing your situation and will be in touch as soon possible.\" <br />
    <br/>
      Best Regards,<br/>
    <br/>
      Company<br/>
    ";
 mail($email, "RE: Contact Form Submission", $intro, $headers);      
 ?>

提前感谢您的帮助。

【问题讨论】:

  • process.php的内容是什么?
  • 我在上面添加了它,但似乎它甚至没有到达 process.php。当使用 include("process.php");我可以让一切正常工作,但我真的很想了解表单插件为什么不起作用。我也在使用 jquery 1.8.0
  • in html action='contact.php' 和 ajax url: 'process.php' 让我很困惑

标签: php jquery html ajax forms


【解决方案1】:

您需要从表单属性中删除onsubmit="return validateForm();。您已经在查询就绪函数中使用 $("#contact").validate({ 进行验证

另外,您的表单似乎是提交给contact.php,而不是process.php

action="contact.php"

【讨论】:

  • 谢谢,hsalama——我认为插件会覆盖表单上的操作,即contact.php?我不希望用户在提交表单后转到 process.php,我希望他们留在 contact.php
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-22
  • 1970-01-01
  • 2015-04-06
  • 1970-01-01
相关资源
最近更新 更多