Jump to content

Parsing Input:checkbox


KittyKate

Recommended Posts

I am feeling rather frustrated and braindead at this point... too many stupid HTML bugs in a day (if only I could at least say that they were because of me, but I'm suffering through another's code!).

I've got the front end working at this point, but here is the setup and please tell me the name/value/id I need to set to get this thing to work.

A pair of radio buttons trigger a javascript for one of two sets of checkboxes to be enabled.

I can figure out which radio button was set, but I'm having issues parsing the checkboxes. The basic idea of the code I'm using is:

[code]<?php
foreach($_POST['name'] as $value) {
    //add $value to database
}
?>[/code]

Is this remotely correct? And will only the the ones that are checked show up, or do I need to test for that (and if so how)?
Link to comment
Share on other sites

Note: pseudo code!!!!

[code]<form name='name1'>
  <input type='radio' onclick='javascript(a)' name='type' value='a' id='a' />A
  <input type='radio' onclick='javascript(b)' name='type' value='b' id='b' />B

  <input type='checkbox' name='a' id='a#' value='#' />String
  <input type='checkbox' name='a' id='a#' value='#' />String
...
  <input type='checkbox' name='b' id='b#' value='#' />String
  <input type='checkbox' name='b' id='b#' value='#' />String
...
</form>
[/code]
Link to comment
Share on other sites

But yes, only the checked checkbox info is posted

Check it out
[code]<?php
if (isset($_POST['submit'])) {
    echo '<pre>', print_r($_POST, true), '</pre><hr>';

?>
<FORM method='POST'>
<input type="checkbox" name="chkbox[1]" value="1"> 1 <BR/>
<input type="checkbox" name="chkbox[2]" value="2"> 2 <BR/>
<input type="checkbox" name="chkbox[3]" value="3"> 3 <BR/>
<input type="checkbox" name="chkbox[4]" value="4"> 4 <BR/>
<input type="checkbox" name="chkbox[5]" value="5"> 5 <BR/>
<input type="submit" name="submit" value="Submit">
</FORM>[/code]
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.