Submit form data values to PHP and thereafter launch PrettyPhoto Lightbox for successful message

948 views Asked by At

I'm working on a project.

I've have form webpage to gather users feedback. After user clicks on the Submit button, the value data that the user enters will pass to send_email.php to email the information to client and user that a new feedback is received. And if it is success, I will print a message that it has sent successfully.

I've a question regarding on printing the successful message. I would like to have the message displays in PrettyPhoto Lightbox. May I know how do I do this?

From what I've researched, the closer script is $.prettyPhoto.open

However, I have problems working on it because I have the post action code. The send_email.php contains the code to send email and display successful message. May I know how do I tweak my code such that the successful message or the error message can display in PrettyPhoto Lightbox?

Thank you very much.

<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 = '[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

There are 1 answers

2
hendr1x On

So I am assuming you don't want comments/help with anything other than getting the popup to appear properly....replace the "Thank you for contacting us..." text with

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