Results 1 to 3 of 3

Thread: Help with array form submission

  1. #1
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default Help with array form submission

    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:
    Code:
    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:
    Code:
    if(@$_POST['submit1'] == 'Submit'){
      $type = $_POST['downloadmethod'];
      $list = $_POST['filelist'];
      $name = date('YmdHis');
      $name .= $user;
      $data = create_archive($name, $list, $type);
      f_download($data);
    }
    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.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    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+.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •