SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Idaho
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Populating list box and passing value

    I have a main web folder that has several sub directories in it. I want to populate a list box with these directories and when the user chooses a value out of the dropdown list it will pass that value to another page.
    html...
    Code:
    
    (test.php) 
    
    
    <form action="done.php" method="post"> 
    <select name = input> 
    <? 
    $dir = "/web/directory/";  //sets directory path 
        
        
          // Open a known directory, and proceed to read its contents 
            
        
    if (is_dir($dir)) 
    {  
        if ($dh = opendir($dir)) 
       { 
            while (($file = readdir($dh)) !== false) //while files and folders are being read    
          {      
                 if (filetype($dir . $file) == dir) //if the filetype is a directory and not a file 
             { 
                  
        echo '<option>'.$file.'</option>'; 
        
             } 
          } 
            closedir($dh); 
       } 
    } 
        
        
    ?> 
    </select> 
    <input type="submit" value="Edit"> 
    
    
    ---------------------------------------------------------------- 
    
    (done.php) 
    
    <html> 
    <form> 
    <input type="text" value="<?echo $_POST["input"]; ?>"> 
    </form> 
    </html>

    The code from the test.php populates the dropdown list just fine but it won't pass the variable selected to done.php. I read that I need to give each option a key but wasn't sure if that was true for my situation or how to go about that.

    Can anyone give me any pointers?

    Thanks!

    edit to add: forgot to put in the echo statement, thanks geharis.
    Last edited by rjseals; Mar 2, 2004 at 12:41.

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <input type="text" value="<?php echo $_POST["input"]; ?>">

  3. #3
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Idaho
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Quote Originally Posted by Gaheris
    <input type="text" value="<?php echo $_POST["input"]; ?>">
    Thanks for pointing that out. I noticed that too after I posted, but unfortunately it still won't pass.

  4. #4

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try a
    PHP Code:
    print_r($_POST); 
    at the top of done.php to see what comes in.

  5. #5
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Idaho
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by drzoid
    Try a
    PHP Code:
    print_r($_POST); 
    at the top of done.php to see what comes in.
    It says

    Array ( [input] => name )

    with name being the name out of the option out of the dropdown list I selected on test.php.

  6. #6

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So the value is correctly passed .... check whether you are doing anything (emptying it, .....) with $_POST or $_POST['input'] between the top of the page and the line where you output it.

  7. #7
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Idaho
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by drzoid
    So the value is correctly passed .... check whether you are doing anything (emptying it, .....) with $_POST or $_POST['input'] between the top of the page and the line where you output it.
    Thanks drzoid, my whole problem was on the done.php. I made a stupid variable mistake. The whole time I was focusing on my code in test.php and all along it was right. Thanks!

  8. #8
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The whole time I was focusing on my code in test.php and all along it was right.
    Yeah, that's what I first did when trying to figure out the error in your script.


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
  •