PHP Classes

Problem with multiple checkboxes

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  Locating addresses on...  >  All threads  >  Problem with multiple checkboxes  >  (Un) Subscribe thread alerts  
Subject:Problem with multiple checkboxes
Summary:Can't find function to set values
Messages:4
Author:Alexey Gradoboev
Date:2007-01-29 13:31:30
Update:2007-01-30 03:39:49
 

  1. Problem with multiple checkboxes   Reply   Report abuse  
Picture of Alexey Gradoboev Alexey Gradoboev - 2007-01-29 13:31:30
Hello, Manuel. Thank you for you greate work and great site. Can you please help me to solve one problem. I'm trying to use multiple checkboxes. But I can't get them working.

The problem concerns functions SetCheckedRadio, SetCheckedState, SetInputValue, SetSelectOptions. I can't understand which one I should use to set values for multiple checkboxes.

--------
For example there are 3 checkboxes with one name (Pets) and different id (dogs,cats,birds), then I get values from the mysql base (from one field 'pets') as array. What function can I use to set values for checkboxes?
--------

And there is another problem. How can I create checkbox fields to look like:

<td>General Label:</td><td>[] - option1<br>[] - option2<br>[] - option3</td>

Is there an oportunity to do something like this:

$form->AddInput(array(
"TYPE"=>"checkbox",
"NAME"=>"q_advanced_search",
"ID"=>"q_advanced_search",
"MULTIPLE"=>"1",
"OPTIONS"=>("VALUE1"=>"OPTION1","VALUE2"=>"OPTION2","VALUE3"=>"OPTION3"),
"LABEL"=>General Label
));

So this field will return the example above:

<td>General Label:</td><td>[] - option1<br>[] - option2<br>[] - option3</td>

where [] - checkboxes.


Do I need to create my one class for that? If so can you give me any help notes how to realise that?

  2. Re: Problem with multiple checkboxes   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-01-29 20:01:37 - In reply to message 1 from Alexey Gradoboev
For this you need to create separate checkboxes for each option. Take a look at the test_form.php example script to see how that can be done. It also demonstrates how to validate them to required at least one of them be checked by the user.

  3. Re: Problem with multiple checkboxes   Reply   Report abuse  
Picture of Alexey Gradoboev Alexey Gradoboev - 2007-01-30 03:03:32 - In reply to message 2 from Manuel Lemos
Thank you for your message. I saw that example. I get them working like in your example. The problem is as follows:

1) There is a form with several fields
2) There is mysql base with values which should be inserted in the form.
3) I use databaseaccess class (http://www.phpclasses.org/browse/package/231.html) to get values from mysql base and insert them into the form.

This class works correctly only with text fields. I've changed it to work with select fields also with using SetSelectOptions() function.

But which function I can use to set values for checkboxes if they are multiple?

There is SetCheckedState() function which can set value for single checkbox. How to work with multiple checkboxes?

  4. Re: Problem with multiple checkboxes   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-01-30 03:39:49 - In reply to message 3 from Alexey Gradoboev
You simply need to use different SetCheckedState calls for each checkbox input.