[thelist] Strange checkbox issue (PHP / Forms)

Hugh Miller hmiller at cfpress.co.uk
Wed Mar 4 05:06:39 CST 2009

Hi folks,

I have a very strange PHP problem processing checkboxes.

I have a form "Add Story". Within this form 'subsections' are chosen by 

<input type="checkbox" name="subsection[]" value="1" /> One
<input type="checkbox" name="subsection[]" value="2" /> Two
<input type="checkbox" name="subsection[]" value="3" /> Three
<input type="checkbox" name="subsection[]" value="4" /> Four

(Please assume that these are enclosed in block level elements, have 
labels etc, the above is for clarity.

To process these the following bit of code is used:

if(isset($_POST['subsection'])) {
   $subsection = implode("|",$_POST['subsection']);
I get the message "Invalid arguments". This appears to be due to 
$subSection being empty (but PHP still thinking it is an array!).

Now, this code has to all intents and purposes been working on an 
earlier version of the CMS, the only changes that have been made are 
styles and layout (upgrading the CMS to WCAG2.0 etc), nothing within the 
functionality has actually been changed.

The only other difference, which is not something I can see causing an 
error, is that the form processor is a function that is called rather 
than a single php script (and I've tried to do it with the processor as 
a script to no avail).

print_r($_POST['subsection']) outputs 'Array' and that is all.

Example of print_r($_POST)  array as received by the form:

Array (
[site_id] => 54
[appeared] => 31-03-2009
[published] => 31-03-2009
[publishHour] => 12
[publishMin] => 30
[headline] => Test
[extra] => Test
[teaser] => Test
[story] => Test
[byline] => 1231
[addByline] => Test
[section_id] => 1
[subsection] => Array  ***
[MAX_FILE_SIZE] => 5500000
[libPic] =>
[pic_caption] =>
[pic_credit] =>
[pic_ref] =>
[comments] => 0
[submit] => Add a Story
[user] =>
[publisher_site_id] =>

Changing the form to $_GET method gives a URL with subsection values 
like this:  &subsection[]=1&subsection[]=2 etc. etc.

The code overall runs to several hundred lines (the output for is 466 
lines long for example and the processor is about 300 lines) so assume 
that I have checked, double and triple checked that there is not a 
conflicting element called subsection being passed anywhere else in the 
form. I have tried putting ID's into subsection[1], have even tried to 
knock off the square brackets in the hope I would receive the last item 

Form opening tag:

<form action="admin/procaddstory/" method="post" 
enctype="multipart/form-data"> (Where procaddstory tells the admin 
script to call the function processStory('procaddstory'), the same 
processor deals with editstory too)

I've been all day with this one! Existing CMS pages are on the same 
server and work perfectly.

If anyone has anyideas I'd greatly appreciate it. (I can provide source 
if necessary for the full form and processing function)

Hugh Miller
Web Developer
Clyde & Forth Press Ltd

Tel:   +44-01475-726511
Fax:   +44-01475-783734
Email: hmiller at cfpress.co.uk

This e-mail and any attachments are confidential and intended solely for the addressee. If you have received it in error, please inform the sender and delete it immediately. The views or opinions contained within this email may not be those of Clyde & Forth Press Ltd, which accepts no liability for any damage caused by the transmission of any viruses. E-mail traffic is monitored within Clyde & Forth Press Ltd and messages may be viewed.

Clyde & Forth Press Ltd is a company registered in Scotland (SC132609) with its registered office at Pitreavie Business Park, Dunfermline, Fife, KY11 8QS.

This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

More information about the thelist mailing list