1

Having trouble figuring out a way to keep my popup/lightbox window open after a user submits a form. I'm a complete beginner at PHP. Right now I just have it going to a message that says "thank you"

If you'd like to see it live, go to http://druvocals.com/dv And click the envelope icon at the top right.

Basically, I want that popup window to stay up after the user clicks "Send" and then just have a little thank you message and then maybe a button that says "Close" and then they will just be right back on the home page. Here's my php code for the form.

   <?php

$EmailFrom = "DruVocals";
$EmailTo = "dru.sing.vocals@gmail.com";
$Subject = "DruVocals";
$Name = Trim(stripslashes($_POST['name'])); 
$Email = Trim(stripslashes($_POST['email'])); 
$Message = Trim(stripslashes($_POST['text'])); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "thanks";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
Sejanus
  • 3,253
  • 8
  • 39
  • 52

2 Answers2

0

Since the "popup" is not actual popup (i.e. separate browser window/tab), upon submiting the form browser goes to forms action url.

A common solution is upon button click to not submit actual form, but collect necessary data and send it to server via javascripts ajax call. That way everything end user sees stays the same. You can display thank you message, error message, close button and anything else depending on what response you get from the server with ajax.

And all of this have very little to do with PHP.

Sejanus
  • 3,253
  • 8
  • 39
  • 52
  • This is a bit advanced for me...is there a site you could link me to that might have a tutorial on how to do this? – Richard Martinez Sep 21 '16 at 09:01
  • @RichardMartinez It's not very complicated, I could write the code example for you, but people already did it for other questions. Try the accepted answer here http://stackoverflow.com/questions/16616250/form-submit-with-ajax-passing-form-data-to-php-without-page-refresh – Sejanus Sep 21 '16 at 10:04
-1

Just redirect to the homepage with some variable. Like:

header('Location: http://druvocals.com/dv/?sended='.$success);

And to the homepage:

<? if( isset($_GET['sended']) && $_GET['sended'] == true ){ ?>
 Some html, like the email sender form popup, just with the message what you want.
<?}?>
Véger Lóránd
  • 5,192
  • 2
  • 14
  • 15