pacome Posted May 8, 2007 Share Posted May 8, 2007 I'm working with a form. I would like to alert the user that leaves a blank field that it is obligatory. After that return him to the previous page... I tried this code but it doesn't work. I can either alert and continue to the next page, or simply return to the previous page without the alert... any ideas how to do it right? thank you... This one doesn't show the popup if (strlen($_SESSION[distribucion]) != "") {echo "Hey got your name. ";} else { echo "<script type='text/javascript'>window.alert('Name is needed!')</script>"; header("Location: notam.php"); } without the header(Location:...) it shows the popup, but then continues... if (strlen($_SESSION[distribucion]) != "") {echo "Hey got your name. ";} else { echo "<script type='text/javascript'>window.alert('Name is needed!')</script>"; //header("Location: notam.php"); } Quote Link to comment Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 What I would do, is code the redirect in the javascript. The header cannot be processed after output is sent to the screen, which is why it would not show the popup. Put a javascript redirect after the window.alert(); and all should be good. Quote Link to comment Share on other sites More sharing options...
pacome Posted May 8, 2007 Author Share Posted May 8, 2007 ;D echo "<script language='javascript'>window.location = 'notam.php'</script>"; you were absolutely right! this little line did the job! thanks. Quote Link to comment Share on other sites More sharing options...
otuatail Posted May 8, 2007 Share Posted May 8, 2007 Something I did in a php web based email //sendemail.php $name = $_POST["Name"]; $from = $_POST["Email"]; if($name == "" || $from == "") { header('Location: ContactUs.php'); exit; } Quote Link to comment Share on other sites More sharing options...
pacome Posted May 8, 2007 Author Share Posted May 8, 2007 right! this one I had... the idea was: how to get a redirect after an alert! with the header(Location:. ..) I was redirected without displaying the javascript alert popup... but adding the redirect in javascript did the trick! thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.