Jump to content

empty field alert and go back


pacome

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.