表单验证成功后,我想使用fancybox插件显示弹出成功的消息。
这是我的PHP代码 -
<?php
if(isset($_POST['cfsubmit'])){
//if no erros, echo the results
if(!$errorExists){
echo "<div id='c_confirm'><p><span class='check_mark'></span>Thank you for contacting With us. One of our customer service representatives will get back to you within 24 hours.</p></div>";
$emailTo = "myemail@gmail.com";
if (!isset($emailTo) || ($emailTo == '') ){
$emailTo = get_option('admin_email');
}
$subject = 'Contact Form from '.$fname;
$body = "First Name: $fname \n\nLast Name: $lname \n\nCheck In date: $check_in_date \n\nCheck Out date: $check_out_date \n\nApartment type: $apart_type \n\nPhone: $phone \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: '.$fname.' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email . "\r\n";
wp_mail($emailTo, $subject, $body, $headers);
}else{
echo "<h3>Error!</h3>".$errors;
}
}?>
我想在弹出框中显示此消息。使用jquery fancybox插件。
<div id='c_confirm'><p><span class='check_mark'></span>Thank you for contacting With us. One of our customer service representatives will get back to you within 24 hours.</p></div>
答案 0 :(得分:1)
假设您已正确加载jQuery和fancybox js和css文件,您可以这样做:
if(!$errorExists){
$fancymessage = "<div id='c_confirm'><p><span class='check_mark'></span>Thank you for contacting With us. One of our customer service representatives will get back to you within 24 hours.</p></div>";
?>
<script>
jQuery(document).ready(function($){
$.fancybox("<?php echo $fancymessage; ?>");
});
</script>
<?php
$emailTo = "myemail@gmail.com";
if (!isset($emailTo) || ($emailTo == '') ){
$emailTo = get_option('admin_email');
}
... etc.
<强> JSFIDDLE 强>