Jump to content

Page Redirect after Error Message is Output to the Browser


makamo66

Recommended Posts

I know that you aren't supposed to output anything to the browser before using the header location function but what if you need to show an error message? If there is an error, for example, an invalid email address, then I want to show an error message and go back to the form submission page. After all of the errors have been corrected, I want to redirect to the next page. However since I already sent an error message, I can't send a header. Is there a way to do this without resorting to javascript?

 

 

Link to comment
Share on other sites

You could try validating with javascript. Tizag.com has a great tutorial on this at http://www.tizag.com/javascriptT/javascriptform.php . it just takes the values, validates them, and displays an alert and will not submit. if there are no errors, the form will submit. I have grown to love this script, as it is quick and easy to use, even for someone who does not know a heck of a lot about javascript.

Link to comment
Share on other sites

As PFMaBiSmAd said, the best approach is the have the form and the process in the same file (usually).  Users will get tired of having to retype everything they put in the form just because one field has a typo.

 

But if I absolutely have to display a message and then redirect, I use the META REFRESH tag. 

<meta http-equiv="refresh" content="2;url=http://domain.com/destination.php">

 

It goes in the HEAD of the HTML document.  The "2" in the content attribute is the number of seconds to wait before loading the page specified in the "url=" portion of the attribute. This gives the user time to read the message.

 

<HTML>
<HEAD>
<META http-equiv="refresh" content="2;url=http://webdesign.about.com">
</HEAD>
<BODY>
<P>That was a very bad thing to do ...</P>
</BODY>
</HTML>

 

Using Javascript to PRE-validate the form is OK, but the user can turn off Javascript, so you HAVE to validate on the SERVER as well.

 

Of course, since the META REFRESH is done by the browser, I suppose it is possible for this feature to be disabled as well.  So you should also have a link in the page that the user can click to go to the page you want them to go to.

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.