将表单数据值提交给PHP,然后启动PrettyPhoto Lightbox以获取成功的消息

时间:2013-08-27 14:22:10

标签: php html forms lightbox prettyphoto

我正在开展一个项目。

我有表格网页来收集用户反馈。用户单击“提交”按钮后,用户输入的值数据将传递给send_email.php,以便将信息通过电子邮件发送给客户端和用户,以便收到新的反馈。如果成功,我将打印一条已成功发送的消息。

我有关于打印成功消息的问题。我想在PrettyPhoto Lightbox中显示消息。我可以知道我该怎么办?

根据我的研究,最接近的脚本是$ .prettyPhoto.open

但是,我在处理它时遇到了问题因为我有post动作代码。 send_email.php包含发送电子邮件和显示成功消息的代码。我可以知道如何调整我的代码,以便成功的消息或错误消息可以显示在PrettyPhoto Lightbox中吗?

非常感谢。

<form id="enquiry_form" method="post" action="send_email.php?iframe=true&amp;width=600&amp;height=300">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="115"><label>Name: </label></td>
                    <td><input class="input_field" type="text" name="name"></td>
                </tr>
                <tr>
                    <td height="10"></td>
                    <td height="10"></td>
                </tr>
                <tr>
                    <td><label>Contact No: </label></td>
                    <td><input class="input_field" type="text" name="contactnum"><br/></td>
                </tr>
                <tr>
                    <td height="10"></td>
                    <td height="10"></td>
                </tr>
                <tr>
                    <td><label>Email Address: </label></td>
                    <td><input class="input_field" type="text" name="emailaddr"><br/></td>
                </tr>
                <tr>
                    <td height="10"></td>
                    <td height="10"></td>
                </tr>
                <tr>
                    <td><label>Message: </label></td>
                    <td><textarea name="message" id="message" rows=7 class="text_field2">Enter your message here</textarea></td>
                </tr>
                <tr>
                    <td height="30"></td>
                    <td height="30"></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td><input id="submit_form" type="image" src="images/buttons/btn_submit.jpg" name="Submit"></td>
                </tr>
            </table>
            </form>

send_email.php:

<?php



function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you have submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
}

// validation expected data exists
if(!isset($_POST['name']) ||
    !isset($_POST['contactnum']) ||
    !isset($_POST['emailaddr']) ||
    !isset($_POST['message'])) {
    died('We are sorry, but there appears to be a problem with the form you have submitted.');      
}

$name = $_POST['name']; // required
$contactnum = $_POST['contactnum']; // required
$email = $_POST['emailaddr']; // required
$msg = $_POST['message']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';


if(!preg_match($email_exp,$email)) {
$error_message .= 'The email address you entered does not appear to be valid.<br />';


}
$string_exp = "/^[A-Za-z .'-]+$/";


if(!preg_match($string_exp,$name)) {
$error_message .= 'The name you entered does not appear to be valid.<br />';
  }


if(strlen($msg) < 2) {
$error_message .= 'The comments you entered do not appear to be valid.<br />';


}

if(strlen($error_message) > 0) {
died($error_message);


}
$email_message = "Form details below.\n\n";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Contact Number: ".clean_string($contactnum)."\n";
$email_message .= "Email Address: ".clean_string($email)."\n";
$email_message .= "Message: ".clean_string($msg)."\n";

$email_from = 'myemail@email.com';
// create email headers

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();



$subject_title = "New Enquiry from ". $name;
$email_body_message = "You have received a new enquiry from " . $name . ", " . $email_message;


mail("myemail@email.com", $subject_title, $email_body_message, $headers);
//send to user
mail($email, "Feedback Received Confirmation", "Dear " . $name . ",\nThank you for contacting us. This is an automated response confirming the receipt of your feedback. We will get back to you as soon as possible.", $headers);
?>


<!-- include your own success html here -->


Thank you for contacting us. We will be in touch with you very soon.
    <?php
//}
?>

1 个答案:

答案 0 :(得分:0)

所以我假设你不想要任何评论/帮助,除了让弹出窗口正常显示....替换“谢谢你联系我们......”文字与

<html><!-- you should probably just include you head file here-->
<body>
<div id="prettyPhoto">Thank you for contacting us. We will be in touch with you very soon.</div>
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
    $("#prettyPhoto").prettyPhoto();
  });
</script>
</body>
</html>