Contact form - when you hit submit, same page confirmation message

Discussion in 'PHP' started by aj22, Jan 13, 2007.

  1. #1
    Hi,

    Right now my contact form redirects to either an error.html or thankyou.html after you hit submit. How can I make it so that the form stays on the same page, and simply inserts a message right under the form saying "Thank you, form submitted" or "Error, please try again"

    Here's my code...

    
    <?php
    include("global.inc.php");
    $errors=0;
    $error="The following errors occured while processing your form input.<ul>";
    pt_register('POST','Name');
    pt_register('POST','Email');
    pt_register('POST','ProjectType');
    pt_register('POST','Industry');
    pt_register('POST','Pages');
    if($Name=="" || $Email=="" || $ProjectType=="" || $Industry=="" || $Pages=="" ){
    $errors=1;
    }
    if($errors)
    {
      header("Location: error.html");
      }
    else{
    $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
    $message="Name: ".$Name."
    Email: ".$Email."
    ProjectType: ".$ProjectType."
    Industry: ".$Industry."
    Pages: ".$Pages."
    ";
    $message = stripslashes($message);
    mail("myemail@here.com","QuickQuote Form",$message,"From: website form");
    
    header("Refresh: 0;url=thankyou.html");
    ?><?php 
    }
    ?>
    
    
    Code (markup):

    Thank you!
     
    aj22, Jan 13, 2007 IP
  2. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <?php
    include("global.inc.php");
    $errors=0;
    $error="The following errors occured while processing your form input.<ul>";
    pt_register('POST','Name');
    pt_register('POST','Email');
    pt_register('POST','ProjectType');
    pt_register('POST','Industry');
    pt_register('POST','Pages');
    if($Name=="" || $Email=="" || $ProjectType=="" || $Industry=="" || $Pages=="" ){
    $errors=1;
    }
    if($errors)
    {
    echo $error;  
    }
    else{
    $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
    $message="Name: ".$Name."
    Email: ".$Email."
    ProjectType: ".$ProjectType."
    Industry: ".$Industry."
    Pages: ".$Pages."
    ";
    $message = stripslashes($message);
    mail("myemail@here.com","QuickQuote Form",$message,"From: website form");
    
    echo 'Thank you message'; 
    ?><?php 
    }
    ?>
    
    
    Code (markup):
     
    maiahost, Jan 13, 2007 IP
  3. aj22

    aj22 Peon

    Messages:
    643
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Those seem to appear on a new page
     
    aj22, Jan 14, 2007 IP
  4. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Could you tell me what your global.inc.php file looks like (whether there's some redirects there). Don't include any mysql usernames/passwords. These should appear on the same page but the form won't display once you've submitted it.
     
    maiahost, Jan 14, 2007 IP
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    Barti1987, Jan 14, 2007 IP