kimjessen Posted September 16, 2014 Share Posted September 16, 2014 Hello! working on something where I need to use the file names in a specific directory. I would like to do it in style with form post and send the result to another php file. What I exactly want to do is. I would like to have a page where I need to be able to do two things. I should be able to enter a value + in a drop down menu should be able to choose one of the file names in the specific custom directory. I have found out how to found the contents of a directory + drop down menu. but I can not exactly figure out how to get it into an post form.? <?php $dir = '/xampp/htdocs/filvar'; $ddArray1 = scandir($dir, 1); //print_r($ddArray1); //echo $ddArray1[5]; PRINT '<select name="Words">'; FOREACH($ddArray1 AS $word){ PRINT '<option value="'.$word.'">'.$word.'</option>'; } PRINT '</select>'; ?> it is basic so far I have come but I would like to get it all into a <form action = "test.php" method = "post"> thing but it managed not right for me. Quote Link to comment Share on other sites More sharing options...
Solution CroNiX Posted September 16, 2014 Solution Share Posted September 16, 2014 The form controls need to be located within the form open (<form>) and close (</form>) tags. <form action = "test.php" method = "post"> <select name="Words"> <?php FOREACH($ddArray1 AS $word){ PRINT '<option value="'.$word.'">'.$word.'</option>'; } ?> </select> </form> 1 Quote Link to comment Share on other sites More sharing options...
CroNiX Posted September 16, 2014 Share Posted September 16, 2014 I also wouldn't use PHP to output HTML except where necessary, like the actual creation of the <option> elements. Quote Link to comment Share on other sites More sharing options...
kimjessen Posted September 17, 2014 Author Share Posted September 17, 2014 (edited) hi there. thanks for a punch in the right direction. with a little tweaking I got what I wanted. <html> <body> <?php $dir = '/xampp/htdocs/php fil var'; $ddArray1 = scandir($dir, 1); ?> <form action = "test_2.php" method = "post"> <select name="file"> <?php FOREACH($ddArray1 AS $file){ PRINT '<option value="'.$file.'">'.$file.'</option>'; } ?> </select> adjustment: <input type="text" name="adjustment"><br> <input type="submit"> </form> </body> </html> Edited September 17, 2014 by kimjessen Quote Link to comment Share on other sites More sharing options...
kimjessen Posted January 21, 2015 Author Share Posted January 21, 2015 (edited) Hey, I'll take this thread up again. I have worked a bit with this piece of code. and now I would like to try something new. instead of send the variable to another file. I would like to use the variable in the same file. I have worked a lot with something in this style. but I can not get the dropdown menu to work, So it is not there, this piece of code, I can get to work but lack the drop down menu, which contains the contents of the library. <html> <body> <form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="text" name="name"><br> <input type="submit" name="submit" value="Submit Form"><br> </form> <?php $dir = './data/test111'; $name = scandir($dir, 1); echo $name[3]; if(isset($_GET['submit'])) { $file = $_GET['name']; echo " <b> $file </b>"; } ?> </body> </html> Edited January 21, 2015 by kimjessen Quote Link to comment Share on other sites More sharing options...
kimjessen Posted January 22, 2015 Author Share Posted January 22, 2015 I have started a new thread this was too cluttered Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.