Passing a form variable into a URL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wolfman
    New Member
    • Apr 2007
    • 21

    Passing a form variable into a URL

    Hi guys

    I have a subdomain with 79 individual episode pages, and I'd like to create a Go! button that allows the user to enter which number page of the group they would like to load, and send them to a different page if the number entered is outside the acceptable range of 01 to 79. This would save 79 links in the site map by replacing all with one link.

    For example, each page is ep01.html, ep02.html through ep79.html. So ideally I'd have a 2-character text input field pre-populated with "01" followed by a Go! button. If the user enters 27 and pushes "Go!" they load ep27.html. However, if the user enters, say, 81, they load episodes.html because the entry is outside the range of pages I have available to choose from.

    Here's the full URL of page one:
    http://series.airwolf. tv/episodes/ep01.html
    and the fallback page:
    http://series.airwolf. tv/episodes/index.html

    I tried experimenting with forms and even JavaScript, but I can't seem to marry the input field result with the href. Any ideas?
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    I didn't see any Form or Input filed on those Pages. how ever i think this will help you to solve your problem.

    you can use this form in your pages.

    [HTML]<form action="redirec t.php" method="post">
    <input name="num" type="text" value="01" maxlength="2" />
    <input name="go" type="submit" value="Go!" />
    </form>[/HTML]

    and the form will call for redirect.php

    [PHP]<?php
    $num = $_POST['num'];
    if($num <= 79)
    {
    $url = 'ep'.$num.'.htm l';
    }
    else
    {
    $url = 'episodes.html' ;
    }
    header ('Location:'.$u rl);
    ?>[/PHP]

    Here i have assumed that all your pages in this format.
    ep[Number].html

    And One more thing, In my PHP script i am not checking whether user entering numbers or characters. how ever if it is numbers script will work as per your requirement.

    Comment

    • Wolfman
      New Member
      • Apr 2007
      • 21

      #3
      Thank you very much - my PHP knowledge is admittedly redimentary, but I learn with each new idea. I had created a series of offline test pages with different script permutations, but I was mainly playing with JavaScript variables and a form field. I look forward to using this script this evening.

      Clark

      Comment

      • Wolfman
        New Member
        • Apr 2007
        • 21

        #4
        Works like a charm! If you'd like to see it in action, here's the link:

        Site map page

        Click AIRWOLF: THE SERIES to find it. I can't thank you enough, ajaxrand, for making a script that saves so much space and has a 'gee whiz' benefit.

        Clark

        P.S. - Would it be too presumptuous to throw out an expansion of this idea? I wonder if this is even possible: when the user types in the number, to the right appears the episode name from a "look-up" list. That way the user is sure it's the one he wants.

        Comment

        • Wolfman
          New Member
          • Apr 2007
          • 21

          #5
          Today a user discovered a little glitch with the code. It's the old single-digit-should-be-a-double-digit problem.

          When a user types in a single digit they get no page at all because the pages are all 01, 02, etc.

          I experimented with an additional if/else command but haven't found the right syntax. What can I use?

          Current script:
          [PHP]
          $num = $_POST['num'];
          if($num <= 79)
          {
          $url = 'ep'.$num.'.htm l';
          }
          else
          {
          $url = 'episodes.html' ;
          }
          header ('Location:'.$u rl);
          [/PHP]

          Things I already tried adding:

          [PHP]if($num <= 10)
          {
          $url = 'ep0'.$num.'.ht ml';
          }
          else[/PHP]

          [PHP]if($num <= [1-9])
          {
          $url = 'ep'.$num.'.htm l';
          }
          else[/PHP]

          Comment

          Working...