View Full Version : Help with array form submission

08-26-2008, 04:00 PM
I need to have a column of check boxes for a column of files. When some of the boxes are checked and the user submits, an array of file names is returned. I will then zip the files and force download of the zipped file.

As an alternate method, the user may just click on a link and a single file will be forced downloaded, and that works fine too. I have all of the parts working with the exception of the returned array - I just can't figure it out even though I know it's done all the time (as on webmail deletes, among others). I seem to be missing something from the online examples. The array needs to be transmitted as a POST. So far, the form code (which is auto generated by the php script) looks like this:
foreach($files as $file => $timestamp){
echo ('<tr><td><input type="checkbox" name="filelist[]" value="' . $file . '"><a href="?file=' . $file . '">' . $file . '</a></td><td></td><td>');
$filesize = filesize($file);
if($filesize >= 1048576){
echo round($filesize / 1048576, 1).'MB';
} else {
echo round($filesize / 1024, 1).'kb';
echo '</td><td></td><td>'.date('M d Y H:i:s', $timestamp)."</td></tr>\n";

Meanwhile, near the top of my script, I have the this:
if(@$_POST['submit1'] == 'Submit'){
$type = $_POST['downloadmethod'];
$list = $_POST['filelist'];
$name = date('YmdHis');
$name .= $user;
$data = create_archive($name, $list, $type);
} The problem is that $list does not contain the array of files checked.....What am I missing? I'd appreciate your help on this one.

08-26-2008, 04:59 PM
http://dynamicdrive.com/forums/showthread.php?t=35911 -- 4.1, possibly 1.4.

I suspect that this is a markup problem. Refactor, validate, and post (all of) the fixed code, please.

08-28-2008, 01:21 PM
Ah, discovered that the code does work for getting an array of checked boxes. I was just not checking the array in the right place - my error. The problem lies elsewhere in a Pear class written in php4+ and I'm using php5+.