Best way to show a new page after submitting a form

Discussion in 'PHP' started by Vijizzle, Jun 16, 2006.

  1. #1
    Hey,

    Ive ust coded my first php contact form.
    Basically I have a normal html page which submits the form to some php script which ensures that some key feilds havnt been left blank and then emails the form to me.

    At the moment the php code just confirms/reports an error through the echo command - which is just a white screen with the message on it.

    I want to get the message to appear as a normal webapge is the bst way to do this to simply write 2 new html pages, one with the error comment and the other with a message sent confirmation and then to use a series of if statements and the include function to decide which page to show.

    or I SOMEHOW reload the form page and pass it a variable which then decides which content to show.
    I guess I could check the submit value from my button....

    I dont know how do you guys normally do it.
    Thanks in advance for any help!
     
    Vijizzle, Jun 16, 2006 IP
  2. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I normally have my validation logic above the HTML or in another file that is included. If all fields are validated it can send the email then redirect to the success page.

    It is important that you do this above the HTML or the redirect will fail since the headers will have been sent.

    Good luck!

    Bobby
     
    Chemo, Jun 16, 2006 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    WIthout seeing the code you should have a mail function. Either Pear or through php's built in library. After that, you will want to redirect your user. Make sure you dont output any data before you redirect or it wont work.

    
    mail($to,$from...);
    
    //redirect user
    header ("location: thankyoupage.php");
    exit();
    
    PHP:
     
    jestep, Jun 17, 2006 IP