check boxes with POST etc

  • JackDaRippaZ
  • Newbie
  • Newbie
  • JackDaRippaZ
  • Posts: 11

Post 3+ Months Ago

Hey all
just wondering if some kind person could help me out. I want to do some reporting upon a database using HTML forms. Yeah? Firstly, now, i have 10 values to chose from each as there own CHECKBOX, which when selected will act as constraints in a selct statement (but i will post messages later when i get deeper into the project, need to nail the basics first) anyways i have:

<input type="checkbox" name="box1" VALUE="1" />
<input type="checkbox" name="box2" VALUE="1" />

etc...right through to

<input type="checkbox" name="box10" VALUE="1" />

Now in a form if the user selects 3 (or any number for that matter) of the CHECKBOXES, assuming they hit SUBMIT in the FORM, and we are using the POST method, what values will be passed to the next page. how are they represented? does it handle all the values? or just the ones

appreciate a response, if someone knows the answer?
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3241
  • Loc: South Africa

Post 3+ Months Ago

The way I usually deal with multiple text boxes is to create an array

the html will look something like
Code: [ Select ]
<input type="checkbox" name="box[]" />

This way you can get all the values entered with something like

PHP Code: [ Select ]
$boxArray = (empty($_POST['box'])) ? "" : $_POST['box'];
for ($i=0;$i<count($boxArray);$i++){
  $result = queryDB($boxArray[$i]); // pseudo code, made the function name up
  $newArray[$i] = $result;
  2. $boxArray = (empty($_POST['box'])) ? "" : $_POST['box'];
  4. for ($i=0;$i<count($boxArray);$i++){
  6.   $result = queryDB($boxArray[$i]); // pseudo code, made the function name up
  8.   $newArray[$i] = $result;
  10. }

nice and clean.

Other wise the best way to check that a checkbox has been selected is
PHP Code: [ Select ]
$newVar1 = (empty($_POST['checkBoxName'])) ? "" : $_POST['checkBoxName'];
$newVar2 = //as above
  2. $newVar1 = (empty($_POST['checkBoxName'])) ? "" : $_POST['checkBoxName'];
  4. $newVar2 = //as above

but that is only if you want to do it the hard way

Good Luck and I hope this helped

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 31 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.