gpt4 book ai didi

forms - 提交联系表时显示感谢信息

转载 作者:行者123 更新时间:2023-12-04 02:48:55 25 4
gpt4 key购买 nike

好的,所以我在论坛上看了看,看到了与此类似的问题,但我仍然无法使用从各个页面窃取的代码。

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

我有以下消息:

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

然后使用此 js 添加“in”以在提交后显示它:

$('#send_button').click(function () {
$('#thanks').addClass('in');
});

$('.close').click(function () {
$(this).parent().removeClass('in'); // hides alert with Bootstrap CSS3 implem
});

我短暂地看到了感谢提醒消息,但随后我被重定向到“process.php”并且它没有显示任何内容,因为其中没有 html,只有 mysql 内容和 php 邮件程序。另一点要注意,无论这是否有趣,我最初通过 ajax 加载联系表单,所以 url 就像 wdr/index.php#contact

谁能帮我完成代码。我确信我缺少一些简单的东西来使它正常工作。

感谢任何帮助。

上校

最佳答案

使用 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();
});
}
});
});

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
}

?>

关于forms - 提交联系表时显示感谢信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18172406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com