1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simple Form Code, Just Can't Find It! Help?

Discussion in 'HTML & Website Design' started by GH Fever, Dec 15, 2008.

  1. #1
    Hey there DP,
    SEMrush
    So I have a simple form code that I really need - Basically what it is, is I want a user to come to a page on my site, enter an access code and be directed to a specific page.

    So like access code 1001 would bring you to (url)1
    And access code 1002 would bring you to (url)2 (a different page)

    Is there anyone that knows how I can do this. I'm sure it's really simple, I just don't know what to search for. :(

    Thanks!
     
    GH Fever, Dec 15, 2008 IP
    SEMrush
  2. pumpkinhootie

    pumpkinhootie Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That sounds simple enough. I have heard of other designers using something like that but I do not know the code. I will try and get it from one of them for you.

    M
     
    pumpkinhootie, Dec 16, 2008 IP
  3. Yesideez

    Yesideez Peon

    Messages:
    196
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here's the PHP:
    $msg='Please enter a code';
    $intNumber=intval($_POST['codenumber']);
    if ($_POST['subcode']) {
      switch ($intNumber) {
        case 1000:header('Location: url1.php');exit;break;
        case 1001:header('Location: url2.php');exit;break;
        case 1020:header('Location: url3.php');exit;break;
        case 3000:header('Location: url4.php');exit;break;
        default:$msg='Code not recognised';
      }
    }
    ?>
    PHP:
    Here's the HTML:
    <?=$msg?><br /><br />
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
      Code: <input type="text" name="codenumber" value="<?=$intNumber?>" /><br />
      <input type="submit" name="subcode" value="Send" />
    </form>
    Code (markup):
    Off the top of my head but should work.

    Just change the lines in the switch() statement to redirect depending on code.

    The default bit prompts the user to enter another code but also tells them the code wasn't recognised.

    btw, the PHP needs to go at the very start of the file BEFORE ANYTHING is sent to the browser, not even a DOCTYPE declaration because headers cannot be modified once anything has been sent to the browser - you'll get an error message and the script will terminate.
     
    Yesideez, Dec 16, 2008 IP
  4. GH Fever

    GH Fever Peon

    Messages:
    432
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Okay - I've placed the code on the page (it LOOKS fine in Firefox, but since the PHP code is before the DOCTYPE it is all screwy in IE, any tips on that)?

    Also, when I type in code '1001' it is bringing me to a 404 Page - <?=$ SERVER[PHP SELF]?> and not the folder /edwardon/ that I'm trying to redirect it too, any clue there? It's perfect and thank you so much, I just need it to go to the actual page when they type their number in.

    Thanks again so much!
     
    GH Fever, Dec 16, 2008 IP
  5. GH Fever

    GH Fever Peon

    Messages:
    432
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm assuming it's in the HTML where the form is trying to link to, but I'm not understanding why it's not going to the correct url.
     
    GH Fever, Dec 16, 2008 IP
  6. Yesideez

    Yesideez Peon

    Messages:
    196
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Any chance of a link to the page?
     
    Yesideez, Dec 16, 2008 IP
  7. SiteTalkZone

    SiteTalkZone Peon

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You could make the PHP a separate page. Direct.php or something then send the form post data to that, that's what I would do.

    It's <?=$_SERVER['PHP_SELF']?> it's an array.
     
    SiteTalkZone, Dec 16, 2008 IP
  8. GH Fever

    GH Fever Peon

    Messages:
    432
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    The link is - HERE

    But don't go in IE because it's all messed up. I had to paste the code provided above the DOCTYPE, so it's messy in IE right now.

    When I type in 1001, it should go to HERE but it's giving me a 404, and I don't get why.

    I'm looking up what an array is, maybe that will help THanks!
     
    GH Fever, Dec 16, 2008 IP
  9. Yesideez

    Yesideez Peon

    Messages:
    196
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    SiteTalkZone - I don't see how it's that that is causing the problem - yes, $_SERVER is an array but ['PHP_SELF'] is referencing an element inside the array - the name of the script.

    You're saying it brings you a 404 page - have you changed the extension of your file to .php and not .html/.htm?
     
    Yesideez, Dec 16, 2008 IP
  10. GH Fever

    GH Fever Peon

    Messages:
    432
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    SiteTalk - are you saying I should put it like this:
    array(<?=$_SERVER['PHP_SELF']?>)
    Code (markup):
    Instead of just the <?=S_SERVER['PHP_SELF']?> ??
     
    GH Fever, Dec 16, 2008 IP
  11. SiteTalkZone

    SiteTalkZone Peon

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Hehe, you don't need to look up what an array is. To me it looks no different in IE7 to FF.

    Something is wrong as the code box shouldn't have <?=$intNumber?> written in it, it should have the value of $intNumber.
     
    SiteTalkZone, Dec 16, 2008 IP
  12. GH Fever

    GH Fever Peon

    Messages:
    432
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I'm bringing it to /edwardon/ - I didn't set it as /edwardon/index.html - just the folder that I need it to go too. Does it have to be set as /edwardon/index.html ???
     
    GH Fever, Dec 16, 2008 IP
  13. Yesideez

    Yesideez Peon

    Messages:
    196
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #13
    GH_Fever - have you renamed the page to .php?
     
    Yesideez, Dec 16, 2008 IP
  14. GH Fever

    GH Fever Peon

    Messages:
    432
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #14
    No, I'm bring it to a folder.

    1001 = /edwardon/
    1002 = /efoveosv/

    Are you saying I should make it /edwardon/index.php?

    They are currently set as index.html
     
    GH Fever, Dec 16, 2008 IP
  15. GH Fever

    GH Fever Peon

    Messages:
    432
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Thank you so much for all the help everyone too - I really, REALLY appreciate it :D
     
    GH Fever, Dec 16, 2008 IP
  16. Yesideez

    Yesideez Peon

    Messages:
    196
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Yes, if you currently have it as index.html you need to change it to index.php then this can be put back:
    <?=$_SERVER['PHP_SELF']?>
    Code (markup):
     
    Yesideez, Dec 16, 2008 IP
  17. SiteTalkZone

    SiteTalkZone Peon

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #17
    I was only saying that because he left the underscores out when he posted the code. I was just checking he had it right.. I'll stay out of it.

    And yes the pages need to have .php extensions :p .
     
    SiteTalkZone, Dec 16, 2008 IP
  18. GH Fever

    GH Fever Peon

    Messages:
    432
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Okay, I changed it and now it looks like this -

    
    <?
    $msg='Please enter a code';
    $intNumber=intval($_POST['codenumber']);
    if ($_POST['subcode']) {
      switch ($redirect) {
        case 1001:header('Location: /edwardon/index.php');exit;break;
        case 1002:header('Location: /marcosds/');exit;break;
        case 1003:header('Location: url3.php');exit;break;
        case 1004:header('Location: url4.php');exit;break;
        default:$msg='Code not recognised';
      }
    }
    ?>
    
    Code (markup):
    And the file is called index.php in the edwardon folder. But I'm still getting the same error message :(
     
    GH Fever, Dec 16, 2008 IP
  19. GH Fever

    GH Fever Peon

    Messages:
    432
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #19

    Oh no, please stay in it SiteTalk. I need all the help I can get please !!
     
    GH Fever, Dec 16, 2008 IP
  20. Yesideez

    Yesideez Peon

    Messages:
    196
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #20
    OK, let's start again :)

    The name of the file with that PHP code inside it must be renamed to end in .php

    Anything inside those header() calls can point to whatever file type you want as long as it's pointing to the files/folders you want them to.

    The reason I've placed the $_SERVER['PHP_SELF'] bit is so that whatever you call the script it will always call itself.
     
    Yesideez, Dec 16, 2008 IP