N00b Question, conditional statements in HTML?

Discussion in 'HTML & Website Design' started by ClayTrainor, Jul 23, 2008.

  1. #1
    Hi,

    Im not very fluent in html, and im trying to do a very simple task. I've been browsing google and multiple forums including this one for a while trying to figure out this basic code but having no luck.

    I believe i may need to use javascript for this.

    What i'm trying to accomplish is:

    - Have visitors enter a confirmation code into a text box
    - If they enter the right code they get sent to my members page
    - If they enter the wrong code they get sent to an error page

    Pretty simple I know, but i cant seem to figure this out.

    i read the tutorial on validation on w3schools, and tested some code out, but i cant seem to get it to work. Im trying to post the code here so i can show you but, im apparently not able to submit "live links" yet.

    Hell, i'll paypal someone $10 to help me with this simple problem asap.
     
    ClayTrainor, Jul 23, 2008 IP
  2. PatMcCrackit

    PatMcCrackit Peon

    Messages:
    109
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well.. your not going to find a way to do it in HTML. JS or PHP is easy enough though.
     
    PatMcCrackit, Jul 23, 2008 IP
  3. iamben

    iamben Active Member

    Messages:
    116
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    73
    #3
    Hey - you could do it in Javascript, I'd do it in PHP - that way you'll never be able to guess the code by looking at the page source. This works absolutely fine. Replace the XXXXX with whatever code you want, yahoo and google with where you want people to go. You'll need to give the page a .php extension (eg- index.php) and you'll need to style any html on the page. Give me a shout if you need any further help. Or want to paypal me $10, haha ;) ben


    
    
    <?php
    
      if (isset($_POST["qcode"])) { 
      
        $getqc = $_POST["qcode"];
        
        if ($getqc == "XXXXX") {
        
          /* Where you want people to go if they get the code right */
          header ("Location: http://www.google.com"); 
          exit;
        
        } else {
        
          /* Where you want people to go if they get the code wrong */
          header ("Location: http://www.yahoo.com"); 
          exit;
        
        }
      
      }
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    
    <title>Question</title>
    
    </head>
    
    <body>
    <form action="index.php" method="post"> <input name="qcode" type="text" /><br><br><input type="submit" name="Submit" value="Submit"> 
    </form>
    
    </body>
    </html>
    
    
    Code (markup):
     
    iamben, Jul 23, 2008 IP
  4. ClayTrainor

    ClayTrainor Peon

    Messages:
    8
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Exactly what i need man, thanks alot!

    Check your pm's.
     
    ClayTrainor, Jul 23, 2008 IP