PHP Checkboxes Not Reading on Submit

I have a form which contains radio boxes:

<li><label for="fd-1"><input type="checkbox" id="fd-1" value="1" name="nActionID[]" />Action option 1</label></li>

<li><label for="fd-1"><input type="checkbox" id="fd-1" value="2" name="nActionID[]" />Action Option 2</label></li>

<li><label for="fd-1"><input type="checkbox" id="fd-1" value="3" name="nActionID[]" />Action Option 3</label></li>

When I post it to the save script, and print out the variable... I get nothing.. I've tried:
print "nAction". $_POST["nActionID[]"]."<br>";
print $nActionID;
print $nActionID[0];

I can't get it.... when i change the form inputs to be singular: <input type="checkbox" name="nActionID" value="1"> then I can get the single record, but naturally I need all checked boxes.

When I submit as GET i see the following:  &nActionID%5B%5D=1&nActionID%5B%5D=2



LVL 1
phenixfilmsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gamebitsCommented:
Checkboxes should have different names because they are independant from each others, if a checkbox is not checked it will not be submitted.
0
phenixfilmsAuthor Commented:
But then I would have do over 100 if statements to check if it were submitted. In dynamic development you are supposed to use somename[] and then php receives all the values as an array.

I created a test script and it works, i think it has to do with the fact that I'm using Fusebox framework....
0
phenixfilmsAuthor Commented:
http://www.fusebox.org/forums/messageview.cfm?catid=6&threadid=4298&FTVAR_MSGDBTABLE=

Theres my solution. I had to access it via $attributes
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

fcardinauxCommented:
Run this script and you will understand how the $_POST['nActionID'] array is filled: it only contains the items that have been checked.
<html><body><form method="post">
<li><label for="fd-1"><input type="checkbox" id="fd-1" value="1" name="nActionID[]" />Action option 1</label></li>
 
<li><label for="fd-2"><input type="checkbox" id="fd-2" value="2" name="nActionID[]" />Action Option 2</label></li>
 
<li><label for="fd-3"><input type="checkbox" id="fd-3" value="3" name="nActionID[]" />Action Option 3</label></li>
<input type="submit">
</form>
<?php
echo '<pre>';
var_dump($_POST);
echo '</pre>';
?>
</body></html>

Open in new window

0
fcardinauxCommented:
In addition to this, you need to give a different id to each checkbox, and therefore a different "for" value to each label.
0
icareyCommented:
Each value will be passed as an array as indicated by [] in name=nActionID[]

when you use action POST the array will arrive as $_POST["nActionID"] you don't need the [] here as you have above.

the array will have 2 values the array key and the value
eg
array key value
      0            1
      1            2
      2            3

All that is needed now is to loop through the array and get the values this can be done by the list function


<form action="action.php" method="POST">
 
<li><input type="checkbox" id="fd-1" value="1" name="nActionID[]" />Action Option 1</li>
 
<li><input type="checkbox" id="fd-1" value="2" name="nActionID[]" />Action Option 2</li>
 
<li><input type="checkbox" id="fd-1" value="3" name="nActionID[]" />Action Option 3</li>
<br />
 
<input type="submit" name="SUBMIT" value="SUBMIT" />
</form>
 
if (empty( $_POST["nActionID"]))
{
	echo "No action Selected"; 
}
else
{
	while (list ($actionkey, $actionval) = each   ($_POST["nActionID"]))
		{
			print "nAction ". $actionval."<br>";               
        }
 
}

Open in new window

0
fcardinauxCommented:
This is an improvement of the code in my previous comment. Both codes are tested.

<html><body><form method="post">
<li><label for="fd-1"><input type="checkbox" id="fd-1" value="1" name="nActionID[]" />Action option 1</label></li>
 
<li><label for="fd-2"><input type="checkbox" id="fd-2" value="2" name="nActionID[]" />Action Option 2</label></li>
 
<li><label for="fd-3"><input type="checkbox" id="fd-3" value="3" name="nActionID[]" />Action Option 3</label></li>
<input type="submit">
</form>
<?php
if ( empty($_POST['nActionID'])) echo 'Please select an action';
else {
    foreach ($_POST['nActionID'] as $action_id) echo "<br>Action $action_id selected";
}    
?>
</body></html>

Open in new window

0
fcardinauxCommented:
You recommend to close the solution as "PAQ'd with a full refund". Moreover the notice says that you have "requested that this question be closed with a full refund and storing the question in our solution database".

If there is a previously asked question (PAQ) on this subject, why store this solution in your database? Why not simply delete it?

If you don't delete it, refunding the points is unfair because icarey's answer was pertinent and because I provided an answer that was tested and worked. The fact that a similar question has already been answered shouldn't cancel out our efforts to help this user. This website is a place where users get help from experts throught exchanges, not a place where competitors race to be the first and only one to answer a specific question. You ask the experts to be patient and not to abandon the users, not to rush and ignore them if they ask a "PAQ". You even write at the bottom of each of your messages: "Please remember that it is important to return to the question you are participating in".

To encourage this behaviour, may I ask you to split the points between icarey and me?

Thank you for your patience.  




0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.