Forum Moderators: coopster

Message Too Old, No Replies

Dynamic Form Processing

How to process an unknow number of variables

         

jbalestrieri

7:54 pm on Feb 1, 2004 (gmt 0)

10+ Year Member



I have a form which I wrote to write captions for graphics in a directory.

The form counts the files in the directory and creates the form field based on the number of files it finds. Here is a stripped down version of the form script.

while ( list( $key, $fileName ) = each( $images ) )
{
if(!empty($fileName) )
{
echo " <td align=\"CENTER\" valign=\"TOP\"><IMG SRC=\"$path/$fileName\" border=0 alt=\"$count\"";
if (!empty($thumb_width)) {echo " width=\"$thumb_width\"";}
if (!empty($thumb_height)) {echo " height=\"$thumb_height\"";}
echo "></a><input name=\"graphic$count\" type=\"text\" value=\"$fileName;\"readonly=\"readonly\">&nbsp;&nbsp;<input type=\"text\"";
echo "name=\"cap$count\"><br>";
if ($count == $break) {
echo "\n </td>\n</tr>\n<tr>\n";
$break = $count + $colunas;
}
else { echo "</td>\n"; }
}
$count++;
}

}
The form that writes the information formats and writes the data to a file.
$input = "$graphic1$cap1\n$graphic2$cap2\n$graphic3$cap3\n$graphic4$cap4\n";

This method works great if there are only 4 pictures, my problem is I do not know how many graphics there will be. Is there a better way to capture the data from this type of dynamic form and format it for writing?

Sanenet

8:22 pm on Feb 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Count the number of files in the directory, and then loop the db entry routine ->

Count.files

Loop while < count.files
=Add to db=

jbalestrieri

8:29 pm on Feb 1, 2004 (gmt 0)

10+ Year Member



The form data is passed to another script for processing, how do I do this in this case? Also I do not write to a data base but write the input to a flat file. So I'm not sure how I would do this.

jbalestrieri

12:17 am on Feb 2, 2004 (gmt 0)

10+ Year Member



OkI was just being an idiot. I loaded everything into an array and the did a count and it worked. Sorry for being so stupid...