当我输入家庭地址和电子邮件Id并单击提交时,电子邮件发送成功。但是它没有在"div class = successbox“中显示成功消息。
我做错了什么?
我有这个index.html
<div class="w-container report">
<h2 class="reportheading"><br><br>Get Your Free On Demand<br>Comprehensive Home Valuation</h2>
<p class="reporttext">Receive current market trends; algorithms; neighborhood facts; comparable listing and sale prices; Sell Time!
<br>
<br>Your custom report is published and returned same day.</p>
<div class="w-form">
<form name="myForm" id="wf-form-Free-Report-2" action="process.php" name="wf-form-Free-Report" data-name="Free Report" method="post" class="reportform">
<div class="w-clearfix formcenter">
<input id="Home" type="text" placeholder="Enter Home Address, City & Zip" name="Home" data-name="Home" required="required" class="w-input formbox spaceright">
<input id="Email-2" type="email" placeholder="Enter Email Address" name="Email-2" data-name="Email" required="required" class="w-input formbox spaceleft">
</div>
<div class="btncenter">
<input id="submit" type="submit" value="Submit" data-wait="Please wait..." class="w-button formbutton">
</div>
</form>
<div class="w-form-done succesbox">
<p>Thank you!
<br>Your Free report will be generated based on your physical address and will be emailed to you shortly.</p>
</div>
<div class="w-form-fail">
<p>Excuse us but something went wrong when trying to submit the form.
<br>Please try again.</p>
</div>
</div>
</div>我有process.php
<?php
$errors = array(); // array to hold validation errors
$data = array(); // array to pass back data
if (empty($_POST['name']))
$errors['name'] = 'Name is required.';
if (empty($_POST['email']))
$errors['email'] = 'Email is required.';
$to = "abc@xyz.com"; // this is your Email address
$from = $_POST['Email']; // this is the sender's Email address
$Home = $_POST['Home'];
$subject = "Request for Comprehensive Home Valuation";
$message = "House Address: ".$Home."<br/>Email Id: ".$from;
error_log("popat11 check this line", 0);
if (mail($to,$subject,$message))
{
$data['success'] = true;
$data['message'] = 'Thank you!
<br>Your Free report will be generated based on your physical address and will be emailed to you shortly.</p>';
}
// return all our data to an AJAX call
echo json_encode($data);发布于 2016-08-12 05:27:16
这被设置为由javascript (AJAX)发起,并由javascript接收/处理。你有支持这个的javascript代码吗?
如果你没有使用javascript,你可以这样修改你的代码(一个非常简单的例子):
<div class="w-form-done succesbox">
<?php if (!empty($_REQUEST['success'])) { ?>
<p>Thank you!
<br>Your Free report will be generated based on your physical address and will be emailed to you shortly.</p>
<?php } else if (!empty($_REQUEST['error'])) ?>
<p>Sorry! There was a problem./p>
<?php } ?>
</div>if ( ! empty($errors)) {
header('Location:index.php?error=1');
} else {
header('Location:index.php?success=1');
}
// echo json_encode($data); /* remove this line */发布于 2016-08-12 05:38:37
看起来您想使用ajax做一些事情( process.php ),然后在原始页面上显示一条适当的消息。您错过了对process.php的ajax调用。
您可以查看http://api.jquery.com/jquery.ajax/来查看一些示例ajax函数。
在对process.php进行ajax调用之后,YOu想要这样做
$( document ).ajaxComplete(function( event,request, settings ) {
$( "#msg" ).append( "<li>Request Complete.</li>" );
});在您的html中,您没有msg id,但是您可以根据返回的数据显示成功或失败,而不是带有“通过”或“失败”内容的div,显示其中一条消息。
希望这能有所帮助。
https://stackoverflow.com/questions/38906256
复制相似问题