Skip navigation
spiderartist
Currently Being Moderated

Entries in a text field would link to different pages

May 7, 2013 4:37 PM

Can anyone help with how to set up a text field so that a number entered will take the user to a specific page?  Different numbers entered would take users to a page specific to that number.

 
Replies
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    May 7, 2013 7:23 PM   in reply to spiderartist

    Are you using a database to store/ fetch your pages based on page numbers? How does your page action work now? Can we see it so we can make better suggestions?

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    May 7, 2013 10:39 PM   in reply to spiderartist

    Assuming you're going to use a database to fetch the data and display it as 10 or 20 items per page and that you'll be loading x number of pages to display all data, the technique is called 'pagination'.

     

    Here are some tutorials that will get you started:

     

    PHP only

    http://net.tutsplus.com/tutorials/php/how-to-paginate-data-with-php/

    http://www.phpeasystep.com/phptu/29.html

    http://papermashup.com/easy-php-pagination/

     

    PHP with jQuery

    http://www.9lessons.info/2009/09/pagination-with-jquery-mysql-and-php. html

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    May 8, 2013 6:38 AM   in reply to spiderartist

    I get it.

     

    I've made a very simple example for you and put it up on my server here: http://sudarshan.me/adobeforum/samples/coupon/index.php

     

    Take a look at it. Here's the code:

     

     

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <title>Test</title>

    <style>

    .container{

        width: 900px;

        margin: 0 auto;

        padding: 50px;

    }

    </style>

    </head>

    <body>

    <div class="container">

    <h1>Validate text from input &amp; display result</h1>

    <h6>100-200 will give you Gift 1. 201-300 will give you Gift 2. Type 'adobe' to see what I love :)</h6>

    <?php

    if(isset($_POST['submit']))

    $code = $_POST['code'];

    {

        if ($code >= 100 && $code <= 200) {

        echo "You have won Gift 1";

    }    elseif ($code >= 201 && $code <=300) {

        echo "You have won Gift 2";

    }    elseif ($code == "adobe"){

        echo "I love Adobe!";

    }

    }   

    ?>

    <form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post">

    <input id="code" name="code" type="text" /><br />

    <input type="submit" name="submit" value="Submit" />

    </form>

    </div>

    </body>

    </html>

     

    This is a straight-forward working example. If your requirement is much more extensive, you can use a MySQL database to determine the input and display a relevant output.

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    May 8, 2013 8:40 PM   in reply to spiderartist

    How many such codes will you have? If it is less in number, you can simply stick to this. If it's a lot and if they're generated new for each user, you're better off using a database to generate, store & verify the codes & display relevant results pertaining to each code.

     

    If you're sticking to this direct method, it's pretty much logical. Note 'elseif' for 2nd condition onwards. If you use only one number, you dont have to give less than or equal to. For example, from 101 - 105, you have 5 codes, you can do this:

     

    if ($code == 101) {

        echo "You have won Gift 1";

    }    elseif ($code == 102) {

        echo "You have won Gift 2";

    }     elseif ($code == 103) {

         echo "You have won Gift 3";

    }     elseif ($code == 104) {

         echo "You have won Gift 4";

    }     elseif ($code == 105) {

         echo "You haev won Gift 5";

    }

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    May 8, 2013 8:41 PM   in reply to Sudarshan Thiagarajan

    Your code will give you the result for both the numbers as you're using 'less than or equal to' and 'greater than or equal to' and will result in a conflict.

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    May 8, 2013 10:55 PM   in reply to spiderartist

     

    There are many scripts out there that can handle this for you - generating & storing coupon codes with relevant benefits from each coupon, set expiry dates, one-time use rules, etc...

     

    Google 'php coupon manager', 'php coupon management', 'php coupon code generator', etc...

     

    Or, you could always hire a PHP professional who could handle this for you and give you a simple-to-use admin interface for managing coupon codes and link it to your front-end page for end-users to use.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points