0

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?

2 Answers 2

1

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']);
}
Sign up to request clarification or add additional context in comments.

6 Comments

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']); } ?>
Correct, but make sure that the original form page has a .php extension on it.
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
You need to put the session_start(); at the very top of the file. Before anything else.
the alert shows up on page load, not after you submit. see it here: v2.ztmag.com/livedates.php
|
0

Replace the header line with:

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

Not tested but should work.

1 Comment

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.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.