the html is wrong, option doesn't have an attribute of name, select has the name,
option has the value.
try it like this, the result will be in $files
<?php
$dir_name = "/path/to/images/directory/";
$dir = opendir($dir_name);
$file_list .= "<p><FORM METHOD=\"post\" ACTION=\"index_done.php3\">
<SELECT NAME=\"files\">";
while ($file_name = readdir($dir)) {
if (($file_name != ".") && ($file_name !="..")) {
$file_list .= "<OPTION VALUE=\"$file_name\">$file_name</OPTION>";
}
}
$file_list .= "</SELECT><br><br><INPUT TYPE=\"submit\" NAME=\"submit\"
VALUE=\"select\"></FORM></p>";
closedir($dir);
?>
----- Original Message -----
From: "Erik Price" <[EMAIL PROTECTED]>
To: "Jas" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, April 08, 2002 6:45 PM
Subject: Re: [PHP] Assigning unique form names...
> I understand what you're saying. You like the convenience of having the
> entire thing kept in a neat variable called $file_list, which you can
> add to your page in any place that you like, but you need a unique name
> for each <select> input tag so that on the "receiving" PHP script, you
> can access the contents of each time that you use $file_list.
>
> Unfortunately, I can't think of a good way for you to make these input
> names unique. The best thing I can suggest is that you turn this into a
> function/subroutine, and pass the string you wish to use as a unique
> name to the function as its argument (and you can make this a reuaseable
> function by also passing the $dir_name as an argument, and the target of
> the form tag). Like this:
>
> // $dir_name = name of directory to list
> // $form_target_page = name of page to receive this form's input
> // $input_name = unique name for this <select> input
> function file_list($dir_name, $form_target_page, $input_name)
> {
> if (!$dir = opendir($dir_name)) {
> return "Could not open directory $dir_name";
> } else {
> $file_start = "<p><form method=\"post\" action=\"$form_target_page\">
> <select name=\"$input_name\">\n";
>
> while ($file_name = readdir($dir)) {
> if ($file_name != '.' && $file_name != '..') {
> $file_list .= "<option
> value=\"$file_name\">$file_name</option>\n";
> }
> }
> closedir($dir);
>
> $file_finish = "</select><br /><br />
> <input type=\"submit\" name=\"submit\"
> value=\"select\">
> </form></p>\n";
>
> // this function prints the form as its return value
> return $file_start . $file_list . $file_finish;
> }
> }
>
>
> On Monday, April 8, 2002, at 12:58 PM, Jas wrote:
>
> > Here is what I need some information about, the script below opens a
> > directory on the server, reads the files and places them into select
> > boxes
> > within a form, now I have this echoed multiple times on the page like
> > so...<? echo "$file_list"; ?> Now I have tried to assign a form name
> > based
> > on the $file_name varibable but because the $file_name variable is
> > created
> > after the form has been created I cannot assign a unique form name each
> > time
> > I call <? echo "$file_list"; ?>. If someone could point out another
> > way to
> > do this or point out a good function for this I would greatly
> > appreciate it.
> > <?php
> > $dir_name = "/path/to/images/directory/";
> > $dir = opendir($dir_name);
> > $file_list .= "<p><FORM METHOD=\"post\" ACTION=\"index_done.php3\">
> > <SELECT NAME=\"files\">";
> > while ($file_name = readdir($dir)) {
> > if (($file_name != ".") && ($file_name !="..")) {
> > $file_list .= "<OPTION VALUE=\"$file_name\"
> > NAME=\"$file_name\">$file_name</OPTION>";
> > }
> > }
> > $file_list .= "</SELECT><br><br><INPUT TYPE=\"submit\" NAME=\"submit\"
> > VALUE=\"select\"></FORM></p>";
> > closedir($dir);
> > ?>
> > Thanks in advance,
> > Jas
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
>
>
>
> ----
>
> Erik Price
> Web Developer Temp
> Media Lab, H.H. Brown
> [EMAIL PROTECTED]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php