2013-08-27 85 views
0

我正在开发一个项目。将表单数据值提交给PHP,然后启动PrettyPhoto灯箱以获得成功消息

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

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

从我的研究,越接近脚本为$ .prettyPhoto.open

不过,我对这个工作的问题,因为我有岗位操作代码。 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._%-][email protected][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 = '[email protected]'; 
// 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("[email protected]", $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

添加一些JavaScript一开始我想像 – allen213

+0

我已经融入到我的谷歌地图查看大图的网页,其中它是一个链接。在这种情况下,它是一个表单提交。我不确定从哪里开始。 $(“area [rel^='prettyPhoto']”)。prettyPhoto(); $(“a [rel^='prettyPhoto']”)。prettyPhoto(); – crank

+0

在您的问题中发布更多代码 – allen213

回答

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> 
+0

嗨hendr1x,我今晚会试一试。 顺便说一句,我现在的验证是在PHP文件中。但是,我想转移到jQuery验证,这是否会干扰PrettyPhoto?从我认为,它不会。 – crank

+0

嗨hendr1x,它不起作用。提交表单后,它会直接发送到send_email.php而不是lightbox。这只是一个简单的信息网页。 – crank

相关问题