1

It redirects them back to the homepage but I want it to also display a box.

if($m->send()){
header('Location:http://blankwebsite.com/');
echo '<script>
alert("Your Quote Request has been submitted!");
</script>';

}
else{
echo $m->ErrorInfo;
}`
  • What you're trying to do doesn't make sense. The header returns a redirect response to the client, which contains no body. (Or even if it does, the browser will just ignore the body.) Redirect *or* display content, not both. – David Jul 01 '16 at 19:16
  • Maybe this is what you want: [displaying a message after redirecting the user to another web page](http://stackoverflow.com/q/12249906/4577762) (<- and this question also has a possible duplicate) – FirstOne Jul 01 '16 at 19:19
  • 1
    To try clearing up the confusion wich was my bad. This part of my script, this script is activated by someone filling out a form and submitting it, I want it to redirect them back to the page where they filled out the form and then notify them that it was sent successfully. If i didn't have a redirect it would keep them on script.php (a blank page) and have a pop up saying it was sent successfully. Sorry for the confusion hope this helps. – Cody Cayetano Jul 01 '16 at 19:49
  • When i had the 2 flipped it would display the notification successfully but then bring me to script.php and show an error "Warning: Cannot modify header information - headers already sent by" – Cody Cayetano Jul 01 '16 at 19:51
  • @CodyCayetano Please consider editing your question instead of commenting for clarity. Also try adding as much details as you can to have more detailled and accurate answers ! – Magix Jul 01 '16 at 20:40

1 Answers1

0

You could save the html in a session variable, display it after redirect and empty the session variable like a flash message at script start up.

if($m->send()){

    $_SESSION['redirectMessage'] = base64_encode(utf8_encode('<script>alert("Your Quote Request has been submitted!");</script>'));

    header('Location:http://blankwebsite.com/');
}
else{
     echo $m->ErrorInfo;
}

On new page request or redirect:

 if isset($_SESSION['redirectMessage']) {
     echo htmlentities(base64_decode($_SESSION['redirectMessage']), ENT_QUOTES, 'utf-8');
      $_SESSION['redirectMessage'] = null;
  }

This solution uses sessions, so do make sure session_start() is called at the top of the script.

Nitin
  • 898
  • 1
  • 9
  • 25