SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jul 2004
    Location
    canada
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    click submit on a form - but how to make it go to "done page"

    hi,

    wondering - ive got a simple html form...


    after a ppl fill it in and hit submit.... is there a way to tell it to go to a page of your choice... eg. thanks.html where you just have a we've recieve your request bit?



    thanks,

  2. #2
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yah, thing is it would have to be a PHP page, because PHP is needed to check if the form was successfully sent:
    Like this could be thanks.php (obviously needs a lot of editing):
    PHP Code:
    if(mail("$blah""blah"$blah"blah")) {
    echo 
    "Successfully sent";
    }
    // or..
    if($submit) {
    echo 
    "form was submitted and there was no error, so you should receive mail soon";

    However, the first is much more recommended.

    And the form would be:
    HTML Code:
    <form method="post" action="thanks.php">
    <input type="text" name="whatever">
    <input type="text" name="whatever">
    <input type="submit" value="Submit">
    </form>
    The action="thanks.php" is the important part here because thats the target page of where your form is submitted and processed.
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  3. #3
    I am obstructing justice. bronze trophy fatnewt's Avatar
    Join Date
    Jul 2002
    Location
    Ottawa, Canada
    Posts
    1,766
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't need to be PHP, specifically. It all depends on what's handling the form on the other side (could be another language, like ASP.NET, for example) The same concept applies though.

    Generally, the action attribute of the form is where the information is sent. You should have the message in that file, after it is processed.

    It depends on how your form is set up.
    Colin Temple [twitter: @cailean]
    Web Analyst at Napkyn


  4. #4
    Non-Member Egor's Avatar
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    7,305
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    <?php

    $MailToAddress 
    "[b]email address[/b]"
    $redirectURL "[b]thank you page address[/b]"
    # ver. 1.2
    $Message "";
        if (!
    is_array($HTTP_POST_VARS))
        return;
    reset($HTTP_POST_VARS);
        while(list(
    $key$val) = each($HTTP_POST_VARS)) {
            
    $GLOBALS[$key] = $val;
            if (
    is_array($val)) { 
                
    $Message .= "<b>$key:</b> ";
                foreach (
    $val as $vala) { 
                    
    $vala =stripslashes($vala);
                    
    $Message .= "$vala, ";
                } 
                
    $Message .= "<br>";
            }     
            else {
                
    $val stripslashes($val);
                if ((
    $key == "Submit") || ($key == "submit")) { }     
                else {     if (
    $val == "") { $Message .= "$key: - <br>"; }
                        else { 
    $Message .= "<b>$key:</b> $val<br>"; }
                }
            }
        } 
    // end while
    $Message "<font face=verdana size=2>".$Message;
    mail$MailToAddress$MailSubject$Message"Content-Type: text/html; charset=ISO-8859-1\r\nFrom: ".$email."\r\nBCc: ".$MailToCC);
    header("Location: ".$redirectURL);
    ?>

  5. #5
    I am obstructing justice. bronze trophy fatnewt's Avatar
    Join Date
    Jul 2002
    Location
    Ottawa, Canada
    Posts
    1,766
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't necessarily need to forward to a thank you address via redirect.

    PHP Code:
      
      
    if (!isset($submitted)) {
      
             
    //Echo the form.  Include a hidden variable called "submitted"
       
     
      
    } else {
      
        
    //Perform processing, count errors in a variable called $errors (or use another method)
     
         
    if ($errors>0) {
               
           
    //Notify user of errors, if any
       
         
    } else {
     
          
    //Print a thank you message
          
    echo("<h1>Form Submitted</h1>");
      
          echo(
    "<p>Thank you, the form has been successfuly sent.</p>");
     
         }
      
      
      } 
    Colin Temple [twitter: @cailean]
    Web Analyst at Napkyn


  6. #6
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That checks if the form was submitted, not if the mail was sent .
    To be double sure, you could do:
    PHP Code:
    if(isset($_POST['submit'])) { //check it was a submitted form

              
    if(mail(blahblahblahblah)) { // check if mail was sent

              
    echo "Sent successfully!";
              
              }

    } else {

    // do error code here...


    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  7. #7
    I am obstructing justice. bronze trophy fatnewt's Avatar
    Join Date
    Jul 2002
    Location
    Ottawa, Canada
    Posts
    1,766
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True. If the form sends mail -- the user hasn't indicated this. A form could also send information to a database, or a file, for example.
    Colin Temple [twitter: @cailean]
    Web Analyst at Napkyn



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •