For the life of me, I can't figure out what's going on here. Every bit of documentation I can find says I'm doing it wrong, but if I do it right it doesn't work the way I need it to. I have a php photo gallery script that allows clients to choose photos they wish to have edited. I want them to be able to choose up to 20 photos per order, but no more than 20. I originally made it so they could choose as many as they wanted, but only 20 get processed but that was confusing for some people. Now I'm adding in a check before the submit to see how many are selected using check boxes and either submit or let them know they picked too many photos.
Under each photo is the check box using the following php code..
if(!in_array($file_names[$count],$check_orders)) $content.="<input type=\"checkbox\" name=\"Edit[]\" value=\"$count\"><font size=\"4\"><b> EDIT PHOTO</b></font><br>";
...and the rest of the code iterates through the photos. The in_array() just checks to see if that photo was already ordered previously. $count is the iteration variable for the photos. That all works. If you haven't noticed what the problem is, it's the name of the check boxes. Edit[]. If the [] brackets are not included, the $_REQUEST['Edit'] variable only returns a single number and not an array of numbers. When I include the [] brackets, $_REQUEST['Edit'] returns the full array of all the numbers associated with the checked photos.
That would be fine, but now as I said, I'm trying to add in a pre-submit check to see if there are more than 20 photos selected. The problem is, JavaScript doesn't recognize Edit[] as an element but it does recognize Edit. No matter what combination I use, I can not seem to get both the pre-submit JavaScript AND the post-submit php to work with the array of check boxes.
All documentation I can find says to name the inputs without the [] brackets and it will automatically be turned into an array. The only place I find a reference to using [] brackets in the name of a form variable is on php.net for a multiple enabled dropdown list selection.
Recap: Everything works on the php side when I use the [] brackets but not on the JavaScript side. Everything works on the JavaScript side when I do NOT use the [] brackets but doesn't work on the php side. Any ideas how to get both working? I'm thinking if nothing else, I'll add another input variable to the form, hidden, and as I do the check to count how many are selected, fill up that variable as an array and pass that on with the form.
Bookmarks