views:

106

answers:

2

Thanks to Col. Shrapnel I am using a VERY basic PHP script to send emails. The form is located here.

This is the script:

<?php
mail('[email protected]','Live Date Submission',implode("\n\n",$_POST));
header("Location: thankyou.html");
?>

When a user submits the form, they are redirected to a thankyou.html page. I want to edit the code to display a javascript alert, instead of a redirect. I don't have much PHP knowledge, so how would I edit this code to return a alert instead of a redirect?

A: 

Replace the header line with:

print("<script>alert('Thank you so very much! You rock!');</script>");

Not tested but should work.

zaf
It does work, howeverr, if redirects you to the email.php page (which is blank white) and then displays the alert. I am looking for the alert to display on the current page without loading another html file.
JCHASE11
+1  A: 

Actually, if you want to send a Javascript alert instead I would recommend using some basic jQuery work. I would also take a look at the AJAX section of the documentation.

Otherwise you can inset some javascript in the original form page.

session_start();
$_SESSION['message'] = "<script>alert('Thank you so very much! You rock!');</script>";
header("Location: originalformpage.html");

and on the original form page

session_start();
if(isset($_SESSION['message']))
{
    echo($_SESSION['message']);
    unset($_SESSION['message']);
}
Josh K
I know Ajax is the proper way to do this, but I am looking for a quick and simple fix. I added the code to mt email.php file and the bottom code to my form file, and I am not getting the alert. It is redirecting to the page, and sending the email, but no alert! Is this correct( below the form) <?php session_start();if(isset($_SESSION['message'])){ echo($_SESSION['message']); unset($_SESSION['message']);}?>
JCHASE11
Correct, but make sure that the original form page has a .php extension on it.
Josh K
I tried that....it says: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/jessechase/ztmag.com/v2/livedates.php:9) in /home/jessechase/ztmag.com/v2/livedates.php on line 233
JCHASE11
You need to put the `session_start();` at the very top of the file. Before anything else.
Josh K
the alert shows up on page load, not after you submit. see it here: http://v2.ztmag.com/livedates.php
JCHASE11
Funny, it works for me. Doesn't show on initial load, shows up after I hit submit. Note that I didn't fill the form out at all.
Josh K