0

After successful form validation, I want to display a popup successful message using fancybox plugin.

Here is my php code -

<?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 = "[email protected]";
    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;
}

}?>

I want to display this message , in a popup box. Using jquery fancybox plugin.

<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 Answer 1

1

Assuming that you have properly loaded jQuery and fancybox js and css files, your could do :

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 = "[email protected]";
    if (!isset($emailTo) || ($emailTo == '') ){
        $emailTo = get_option('admin_email');
    }
    ... etc.

JSFIDDLE

1
  • @hocpana You should consider accepting the answer if it works for you. That way we know your problem is solved.
    – AyB
    Commented May 11, 2014 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.