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"); } Link to comment https://forums.phpfreaks.com/topic/50552-empty-field-alert-and-go-back/ 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. Link to comment https://forums.phpfreaks.com/topic/50552-empty-field-alert-and-go-back/#findComment-248395 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. Link to comment https://forums.phpfreaks.com/topic/50552-empty-field-alert-and-go-back/#findComment-248411 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; } Link to comment https://forums.phpfreaks.com/topic/50552-empty-field-alert-and-go-back/#findComment-248433 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! Link to comment https://forums.phpfreaks.com/topic/50552-empty-field-alert-and-go-back/#findComment-248451 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.