Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Redirect by form entry

  1. #11
    Join Date
    Jan 2007
    Posts
    82
    Thanks
    30
    Thanked 18 Times in 17 Posts

    Default

    Thanks Jas, and dcstow. You've both been very helpful, and I think I've accomplished what I needed. I now have an input box where an inputted string is converted to lowercase, and processed, then redirecting the user to the appropriate page. Awesome!

    One thing I am ehh, "semi" worried about was one of Jas' comments about a 30 or 40 case maximum. As I grow these pages, it will inevitably reach that number, and of course, for each new page I must also edit this php page. What are my options to the case method? If every "case" identically matched all my page names, would the "case method" no longer be the logical choice?

    Can't I just validate, convert to lowercase, add ".html" and pass the variable directly into the location code? Therefore directing a user to the appropriate page?

  2. #12
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    You could, I suppose, but it would be a lot of code. A better way would be something like this:
    PHP Code:
    $names = array();
    $urls  = array();

    $names[] = "BOB";  $urls[] = "bob.html";
    $names[] = "BILL"$urls[] = "bill.html";
    $names[] = "BART"$urls[] = "bart.html";

    $page array_search($name$names);

    if(
    $page == false){
        
    $page "Somthing.html"// <--Back to the form, or a not found page
    }else{
        
    $page $urls[$page];

    It's MUCH smaller then a case for each name. You could also pull the array out of another file, if you ever needed to. It gives you many more options.

    EDIT: Oh, or the easier solution:
    PHP Code:
    $names = array();

    $names[] = "BOB";
    $names[] = "BILL";
    $names[] = "BART";

    $page array_search($name$names);

    if(
    $page == false){
        
    $page "Somthing.html"// <--Back to the form, or a not found page
    }else{
        
    $page $names[$page].'html';

    Last edited by Jas; 02-15-2008 at 09:55 PM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. The Following User Says Thank You to Jas For This Useful Post:

    tonyking (02-18-2008)

  4. #13
    Join Date
    Jan 2007
    Posts
    82
    Thanks
    30
    Thanked 18 Times in 17 Posts

    Default

    This code is now presenting me with a problem in IE, and I can't for the life of me figure out why!? I am using a page called registry.php, here's the code:

    PHP Code:
    <?php
        
    if(isset($_POST['Submit'])){
            
    $name strip_tags($_POST['name']);
            
    $name strtolower($name);
            switch(
    $name){
                case 
    "haynes":
                    
    $page 'haynes.html';
                break;
                case 
    "bill":
                    
    $page 'bill.html';
                break;
                case 
    "bart":
                    
    $page 'bart.html';
                break;
                default:
                    
    $page "noregistry.html";
                break;
            }
            
    header("Location:$page");
        }
    ?>
    And I am using the below form to post to the script.

    HTML Code:
    <form name="Submit" method="post" action="registry.php">
    <input type="text" name="name" class="cleardefault" size="20" value="Groom's Last Name" /><br />
    <font size="-2" color="#0099FF">(Use ALL lowercase letters)</font><br /><br />
    <input type="Submit" name="Submit" value="Submit" />
    </form>
    It works in firefox, and upon original testing, it worked in IE. Now when I test in IE it takes me to the registry.php page and stops. The script does not redirect to the appropriate case or page.

    Here's the live example:
    www.damartravel.com/honeymoons.html
    You can see the form in the left hand column.

    Here's the direct link to the page it should redirect to:
    www.damartravel.com/haynes.html

    Hopefully this is something silly, and one of you know what it is! lol... It's been driving me crazy all morning.

    Thanks in Advance.

  5. #14
    Join Date
    Mar 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey guys!

    The script is working fabulous !

    Just wondering however is there a code to protect the pages? So they have to of logged in that field to get to Bob.html and so no other users can go directly to Bob.html?

    Much appreciated, Keenan.

  6. #15
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    @TonyKing,
    I'm not fluent in PHP, but as I see, your code has some errors
    See the header() function spec. There should always be http://

    Also, I suppose you should post name instead of submit

    Try changing your PHPcode to:
    PHP Code:
    <?php
        
    if(isset($_POST['name']))
        {
            
    $myweb 'http://www.damartravel.com';
            
    $name strip_tags($_POST['name']);
            
    $name strtolower($name);
            
            switch(
    $name)
            {
                case 
    "haynes":
                    
    $page $myweb.'/haynes.html';
                    break;
                case 
    "bill":
                    
    $page =  $myweb.'/bill.html';
                    break;
                case 
    "bart":
                    
    $page =  $myweb.'/bart.html';
                    break;
                default:
                    
    $page =  $myweb.'/noregistry.html';
                    break;
            }
            
    header("Location:".$page);
        }
    ?>
    See if helps

    @Keenan
    You should use the forum's search tool, or create a new thread instead, You should'nt hi-jack someone else's thread
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  7. The Following User Says Thank You to rangana For This Useful Post:

    tonyking (03-30-2008)

  8. #16
    Join Date
    Jan 2007
    Posts
    82
    Thanks
    30
    Thanked 18 Times in 17 Posts

    Default

    Thanks ragana, your code is far more solid than my original, and I will put it to good use. The "problem" I found with my script(s) was in a javascript, as it only fails when the user pushes enter on the keyboard, instead of clicking submit.

    Corresponding thread: click here

    Definite improvement on the code though! Thanks

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
  •