Forms 提交联系人表单时显示感谢信息

Forms 提交联系人表单时显示感谢信息,forms,twitter-bootstrap,alert,contact,Forms,Twitter Bootstrap,Alert,Contact,好的,我在论坛上看到了类似的问题,但是我仍然没有从不同的页面上获取代码 我使用bootstrap css来显示联系人表单、常用字段、姓名电子邮件、消息等。action=“process.php”是我将用户添加到mysql数据库中,然后通过电子邮件向我确认有人提交了表单。所以在这方面一切都很好,只是我想在表单提交后显示一条简单的“谢谢”消息,而不是重定向到另一个页面 我有以下消息: <!-- thank you message --> <div id="thanks" class

好的,我在论坛上看到了类似的问题,但是我仍然没有从不同的页面上获取代码

我使用bootstrap css来显示联系人表单、常用字段、姓名电子邮件、消息等。action=“process.php”是我将用户添加到mysql数据库中,然后通过电子邮件向我确认有人提交了表单。所以在这方面一切都很好,只是我想在表单提交后显示一条简单的“谢谢”消息,而不是重定向到另一个页面

我有以下消息:

<!-- thank you message -->
<div id="thanks" class="alert alert-success fade">
  <button href="#" type="button" class="close">&times;</button>
  <h4>Got it!</h4>
  <p>Thanks. I've received your message, I'll be in touch within 24 hours. Promise.</p>
</div>
我简短地看到了感谢您的提醒消息,但随后我被重定向到“process.php”,它没有显示任何内容,因为里面没有html,只有mysql和php邮件。 需要注意的另一点是,不管这是否有趣,我最初是通过ajax加载联系人表单的,因此url类似于wdr/index.php#contact

有人能帮我完成代码吗。我相信这是我错过的一些简单的东西,使这项工作,因为它应该

谢谢你的帮助


Col

使用Ajax使它变得简单。以下是我用于简单发送的内容:

js:

$('#form_id').on('submit', function(e) {
    e.preventDefault(); //Prevents default submit
    var form = $(this); 
    var post_url = form.attr('action'); 
    var post_data = form.serialize(); //Serialized the form data for process.php
    $('#loader', form).html('<img src="../img/forms/loader.gif" /> Please Wait...');
    $.ajax({
        type: 'POST',
        url: 'process.php', // Your form script
        data: post_data,
        success: function(msg) {
            $(form).fadeOut(500, function(){
                form.html(msg).fadeIn();
            });
        }
    });
});
$('form#u id')。关于('submit',函数(e){
e、 preventDefault();//防止默认提交
变量形式=$(此);
var post_url=form.attr('action');
var post_data=form.serialize();//序列化了process.php的表单数据
$('loader',form).html('Please Wait…');
$.ajax({
键入:“POST”,
url:'process.php',//您的表单脚本
数据:post_数据,
成功:功能(msg){
$(形式).fadeOut(500,函数(){
html(msg.fadeIn();
});
}
});
});
process.php:

<?php

/* Configuration */
$subject = 'Submission received'; // Set email subject line here
$mailto  = 'your email address'; // Email address to send form submission to
/* END Configuration */

$firstName      = $_POST['firstName'];
$lastName       = $_POST['lastName'];
$email          = $_POST['email'];
$companyName    = $_POST['companyName'];
$phone          = $_POST['phone'];
$callTime       = $_POST['callTime'];
$timestamp = date("F jS Y, h:iA.", time());

// HTML for email to send submission details
$body = "
<br>
<p>The following information was submitted through the contact form on your website:</p>
<p><b>Name</b>: $firstName $lastName<br>
<b>Email</b>: $email<br>
<b>Company name</b>: $companyName<br>
<b>Phone number</b>: $phone (Please call in the <b>$callTime</b>)</p>
<p>This form was submitted on <b>$timestamp</b></p>
";

// Success Message
$success = "
<div class=\"row-fluid\">
    <div class=\"span12\">
        <h3>Submission successful</h3>
        <p>Thank you for taking the time to contact Pacific One Lending. A representative will be in contact with you shortly. If you need immediate assistance or would like to speak to someone now, please feel free to contact us directly at <strong>(619) 890-3605</strong>.</p>
    </div>
</div>
";

$headers = "From: $firstName $lastName <$email> \r\n";
$headers .= "Reply-To: $email \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>$body</body></html>";

if (mail($mailto, $subject, $message, $headers)) {
    echo "$success"; // success
} else {
    echo 'Form submission failed. Please try again...'; // failure
}

?>


嘿,谢谢你的回复和密码。从我所看到的情况来看,这仍然会将感谢信息加载到与联系人表单不同的页面中。我希望在表单提交后,在表单旁边“显示”一条感谢信息,而无需重新加载页面。我认为这是一件容易的事情,只是不能把代码写出来。另外,我喜欢你的邮件代码,我会用的!实际上,应该加载Thankyou块来代替表单。如果你能在JSFIDLE上发布你的代码,我会看一看问题出在哪里。嗯,很难把它放到FIDLE上,并按照我的方式工作。我相信你是对的,因此,我将在这段时间内处理代码,并让你知道。谢谢你的时间和建议。只是一个快速更新,正如预期的那样,我做了一些错误的事情,你的代码工作得很好。非常感谢提交,这真的帮了我很多忙。干杯
<?php

/* Configuration */
$subject = 'Submission received'; // Set email subject line here
$mailto  = 'your email address'; // Email address to send form submission to
/* END Configuration */

$firstName      = $_POST['firstName'];
$lastName       = $_POST['lastName'];
$email          = $_POST['email'];
$companyName    = $_POST['companyName'];
$phone          = $_POST['phone'];
$callTime       = $_POST['callTime'];
$timestamp = date("F jS Y, h:iA.", time());

// HTML for email to send submission details
$body = "
<br>
<p>The following information was submitted through the contact form on your website:</p>
<p><b>Name</b>: $firstName $lastName<br>
<b>Email</b>: $email<br>
<b>Company name</b>: $companyName<br>
<b>Phone number</b>: $phone (Please call in the <b>$callTime</b>)</p>
<p>This form was submitted on <b>$timestamp</b></p>
";

// Success Message
$success = "
<div class=\"row-fluid\">
    <div class=\"span12\">
        <h3>Submission successful</h3>
        <p>Thank you for taking the time to contact Pacific One Lending. A representative will be in contact with you shortly. If you need immediate assistance or would like to speak to someone now, please feel free to contact us directly at <strong>(619) 890-3605</strong>.</p>
    </div>
</div>
";

$headers = "From: $firstName $lastName <$email> \r\n";
$headers .= "Reply-To: $email \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>$body</body></html>";

if (mail($mailto, $subject, $message, $headers)) {
    echo "$success"; // success
} else {
    echo 'Form submission failed. Please try again...'; // failure
}

?>