form question... please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bubs
Forum Newbie
Posts: 11
Joined: Wed Aug 16, 2006 12:19 pm

form question... please help

Post by bubs »

I have a form that works but everything is in one file. I want to separate the thank you page from the rest of the stuff. How would I go about doing that?

is there a redirect snippet or something I can put in there so that when it tries to display the thanks you it would redirect you to the html page i have instead?
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Post by SpecialK »

This was recently answered

viewtopic.php?t=56415

Your modification to it would be something along these lines

Code: Select all

if($validated){

   header("location: http://www.yoursite.com/thank_you.html");
}else{
  //the code to display to the user because it is not validated
}
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Let's promote good practice here... make sure no headers have been sent first.

Code: Select all

function redirect($location){
    if(!headers_sent()){
        header('Location: ' . $location);
    }
    else{
        echo "<a href='" . $location . "'>Continue</a>";
    }
    exit;
}
if($validated){
   redirect("http://www.yoursite.com/thank_you.html");
}else{
  //the code to display to the user because it is not validated
}
bubs
Forum Newbie
Posts: 11
Joined: Wed Aug 16, 2006 12:19 pm

fantastic

Post by bubs »

Very cool! Thanks guys
Dave2000
Forum Contributor
Posts: 126
Joined: Wed Jun 21, 2006 1:48 pm

Post by Dave2000 »

Just a quick question. I often see people checking if a header has been sent before redirecting. However, what is the point in this? Surely if a header has been sent, you will see it has when you test the script...

Shears :)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

umm... I generally don't like PHP Errors to show up on my web sites... for some strange reason I just feel that it's unprofessional. :roll:

That's kind of a strange question... that's like asking... "Why would you check that there is a database connection before attempting to use one... when PHP would report this via an Error?"

As a programmer, it's your responsibility to be paranoid and trust nothing.
Post Reply