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. Link to comment https://forums.phpfreaks.com/topic/291109-form-post-with-array/ Share on other sites More sharing options...
CroNiX Posted September 16, 2014 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> Link to comment https://forums.phpfreaks.com/topic/291109-form-post-with-array/#findComment-1491327 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. Link to comment https://forums.phpfreaks.com/topic/291109-form-post-with-array/#findComment-1491328 Share on other sites More sharing options...
kimjessen Posted September 17, 2014 Author Share Posted September 17, 2014 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> Link to comment https://forums.phpfreaks.com/topic/291109-form-post-with-array/#findComment-1491380 Share on other sites More sharing options...
kimjessen Posted January 21, 2015 Author Share Posted January 21, 2015 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> Link to comment https://forums.phpfreaks.com/topic/291109-form-post-with-array/#findComment-1503661 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 Link to comment https://forums.phpfreaks.com/topic/291109-form-post-with-array/#findComment-1503672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.