1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

PHP Passing Hidden Form Field

Discussion in 'Web Design & Development' started by smooth, Mar 10, 2009.

Thread Status:
Not open for further replies.
Advertisement
  1. smooth

    smooth Thread Starter

    Joined:
    Sep 26, 2005
    Messages:
    4,016
    Hey everybody :)

    I have a php page with the following form on it:

    PHP:
            <form action="" method="post">
            <input type="hidden" name="random" value="<?php echo $random?>" />
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td align="center">
                            Code 1
                            <br />
                            <input name="code1" type="text" />
                        </td>
                        <td align="center">
                            Code 2
                            <br />
                            <input name="code2" type="text" />
                          </td>
                        <td align="center">
                            Code 3
                            <br />
                            <input name="code3" type="text" />
                          </td>
                    </tr>
                    <tr>
                         <td align="center">
                            Code 4
                            <br />
                              <input name="code4" type="text" />
                          </td>
                        <td align="center">
                            Code 5
                            <br />
                            <input name="code5" type="text" />
                          </td>
                        <td align="center">
                            Code 6
                            <br />
                            <input name="code6" type="text" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" align="center">
                            <br />
                            <input type="submit" name="submit" value="Submit" />
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="reset" name="reset" id="reset" value="Reset" />
                           </td>
                    </tr>
                </table>
            </form>
    In order to determine where the user goes when submitting the form, I have the following code at the top of the same page:

    PHP:
    $random rand(150000950000);
    session_start();
    if(isset(
    $_POST['submit']))
    {
    $strCode1 $_POST['code1'];
    $strCode2 $_POST['code2'];
    $strCode3 $_POST['code3'];
    $strCode4 $_POST['code4'];
    $strCode5 $_POST['code5'];
    $strCode6 $_POST['code6'];

    $code1 strtolower($strCode1);
    $code2 strtolower($strCode2);
    $code3 strtolower($strCode3);
    $code4 strtolower($strCode4);
    $code5 strtolower($strCode5);
    $code6 strtolower($strCode6);

    if ( 
    $code1 == "this" && $code2 == "code" && $code3 == "works" && $code4 == "really" && $code5 == "well" && $code6 == "yay" ) { 
        
    $_SESSION['confirmed'] = true;    
        
    header('Location: yay.php');
        exit;
    } else {
        
    $_SESSION['confirmed'] = false;
        
    header('Location: boo.php');
        exit;
    }
    }
    That works perfectly, as far as getting the user to the correct page, based on if they put in the correct code or not.

    However, what I want to do, is access the number that is generated by this line:

    PHP:
    <input type="hidden" name="random" value="<?php echo $random?>" />
    on either "yay.php" or "boo.php".

    I've tried $_GET and $_POST when trying to access it on those pages, but can't seem to get it right.

    Any ideas or suggestions are greatly appreciated :)
     
  2. MMJ

    MMJ Guest

    Joined:
    Oct 15, 2006
    Messages:
    3,625
    Don't exactly follow.

    $_POST['random'] isn't set?
     
  3. dudeking

    dudeking

    Joined:
    Feb 7, 2007
    Messages:
    483
    You may need an id and a name
     
  4. thebeginner

    thebeginner

    Joined:
    Feb 13, 2008
    Messages:
    29
    When opening a dialog in Visual Basic, Visual C# or other programming languages Windows has to know the name of the dialog. This I believe is the case here. Instead though the ID and Name is needed. The server needs to know where to place the charactors. I believe it's the server that's involved here.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/808072