Log in

View Full Version : php popup box to replace form redirect page?



moscarda
01-29-2009, 04:58 AM
i've installed a simple php mail script, which redirects to a thank you / follow-up page after verifying user-inputted content. rather than ending up here, i'd prefer to not leave page with the form at all, and instead have a popup alert box simply say "thanks for your message!" with an "ok" button. then, when you click ok, it refreshes the page so you are right back where you started off.

heres my php code:



<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Go Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}


$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = 'Message from mydomain.com';

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Message: $notes \n
From: $visitor ($visitormail)\n
";

$from = "From: $visitormail\r\n";


mail("myemail@mydomain.com", $subject, $message, $from);

?>


how can i achieve this?

Nile
01-29-2009, 05:04 AM
Right now I don't see where your redirecting the user. But one thing that you do to validate that the email has been sent is:


if(@mail($data..)){
header();
}

To not re-load the page at all. You would have to learn/use ajax (http://www.w3schools.com/Ajax/Default.Asp). If your lazy and don't really want to learn an extension to javascript - use jquer (http://docs.jquery.com/Ajax)y - an extension to javascript ;). And for the popup, use the "Open Dialog" button(you'd need to download a jquery style/format) located here (http://ui.jquery.com/themeroller).

Good luck - Your brave, I would never attempt this. :)

moscarda
01-29-2009, 05:10 AM
hmm, i dont think what i'm trying to do is as advanced as youre thinking.

the code pasted above IS the page that gets redirected to when the form posts:


<form method="post" action="email.php">


i could just append the php file with something like:


?>
<script type="text/javascript">
alert("Thanks for your message!");
history.go(-2);
</script>
<?php

but that still won't keep me from navigating away from the original page with the form. am i making sense?

Nile
01-29-2009, 12:58 PM
You can't do this without ajax... Try this (http://dynamicdrive.com/dynamicindex4/facebox/index.htm). Then with ajax you would have to send the POST data... (if your validating to make sure that the page is valid.