By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,302 Members | 1,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,302 IT Pros & Developers. It's quick & easy.

Processing Checkbox Arrays

P: 1
G'day folks,

I have an intriguing question, one which most programmers have been talking around, and the solutions I have seen posted often inadequate:

<INPUT TYPE=CHECKBOX NAME="Profession[]" value="">Musician<BR>
<INPUT TYPE=CHECKBOX NAME="Profession[]" value="">Banker<BR>
<INPUT TYPE=CHECKBOX NAME="Profession[]" value="">Broker<BR>
<INPUT TYPE=CHECKBOX NAME="Profession[]"value="">Photographer<BR>
<INPUT TYPE=CHECKBOX NAME="Profession[]" value="">Actor<BR>

Now processing these checkboxes as the Array "Profession" is not so much the problem, but rather:

$_POST['Profession'] will hold the array of checkboxes, since they will either be "checked" or "unchecked" { "true" or "false"}.

From what I understand, when a checkbox is not ticked, it will not be in the array as an element, is this correct thinking?

Secondly, if I want it to be in a "sticky form", how would I achieve this? Do I need to make the "value" attrib in my <input ... tag to be: value="Actor" or "photographer" etcetc....

then :
value=" <?php isset($_POST['Profession']['Actor']) ? $_POST['Profession']['Actor'] : "" ?> "

Would this achieve the desired effect? I expect this to be a boolean: ON or OFF { checked / unchecked OR 1 / 0}

To search for it in the array, I expect to associate the profession name such as "Actor" to distinguish it from "Banker", so I know which checkbox has been ticked.

Am I on the right path here, cause I cannot get my scripts to return the correct results when they check these checkbox arrays.

So what am I engineering wrong:

$checkbox_arr = $_POST['Profession'];

I now wish to know if there are any checked boxes in this array as such:
If (empty($checkbox_arr)){
do something +ve
do something -ve

Does this make sense folks??? < drop me an email if you have something useful to impart :>

Cheers in advance.

Have a nice day.
Jan 20 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.