[thelist] Multiple form entries in PHP...

Garrett Coakley garrett at polytechnic.co.uk
Fri Nov 30 09:10:20 CST 2001


On Fri, 2001-11-30 at 14:43, Mike King wrote:

> The reason I wanted to use fields with multiple entries, was that I don't 
> know how many fields there will be. (It's an FTP app that that you can 
> choose files to be uploaded from a list, so even if I knew the total number 
> of items, they may not all be checked)

(I've just given mike the answer on #evolt, but I'll post it here for
anyone else who wants it)

In this kind of situation, where you don't want to create unique
variables, then the easiest thing to do is this:

<form action="whatever.php" method="post">
<p>Check 1: <input type="checkbox" name="file[]" value="foo"></p>
<p>Check 2: <input type="checkbox" name="file[]" value="bar"></p>
<p>Check 3: <input type="checkbox" name="file[]" value="pub"></p>
</form>


When the form is submitted php will create a zero based array called
$file containing the checked items.

>From there you can get the number of items with count($file) and
retrieve them with $file[n].

Thats the general gist anyway.
 
G.

--
----------------------------------------------------------------------------
WORK: http://spiked.co.uk/
PLAY: http://polytechnic.co.uk/





More information about the thelist mailing list