Jump to content

Passing multible check box values to another page


son.of.the.morning

Recommended Posts

Give all the checkboxes an array name such as:

 

<input type="checkbox" name="checkBoxArray[]" ...

 

Then give each individual checkbox a unique value corresponding to the row ID:

 

<input type="checkbox" name="checkBoxArray[]" value="<?php echo $rowIDarray[1]; ?>" /> <input type="checkbox" name="checkBoxArray[]" value="<?php echo $rowIDarray[2]; ?>" />

 

Where $rowIDarray would be an array of all the unique row ID's the user can select.

 

Then, to process the response, you simply need to loop through checkBoxArray, each of it's corresponding values with be the ID of a row which was checked. If it's empty, no items were checked.

Link to comment
Share on other sites

Actually, I may have made an error. I particularly hate trying to use the value attribute with checkboxes specifically because it can lead to this error.

 

I typically try to avoid this type of logic because I can never remember if an unchecked checkbox whose name is a PHP array with an incrementing index will make a new array entry and set it to the boolean false. In fact, I think this is what it will do, and a heads up to your logic when processing the response: you'll have to make sure the ID you're getting back isn't equal to (==) the empty string ( '' ) because unchecked checkboxes will probably make a new array index that is set to the empty string.

Link to comment
Share on other sites

I can never remember if an unchecked checkbox whose name is a PHP array with an incrementing index will make a new array entry and set it to the boolean false. In fact, I think this is what it will do

 

Unchecked checkboxes are never reported, they are left out of the request entirely.  PHP will only know about the ones that were checked, and their values will be whatever the value attribute is.  There won't be any empty elements filling in for unchecked boxes.

 

Link to comment
Share on other sites

Unchecked checkboxes are never reported, they are left out of the request entirely.  PHP will only know about the ones that were checked, and their values will be whatever the value attribute is.  There won't be any empty elements filling in for unchecked boxes.

 

Thanks for the clarification, I usually wind up making the index's named for the ID and allow them to be set to checked if they were check to avoid the issue entirely since I can never remember.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.