Jump to content

form post with array


kimjessen
Go to solution Solved by CroNiX,

Recommended Posts

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
Share on other sites

  • Solution
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>

  • Like 1
Link to comment
Share on other sites

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 by kimjessen
Link to comment
Share on other sites

  • 4 months later...
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 by kimjessen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.