Forums

Checkbox group handling

Lesanjo 16 Jun, 2012
Hello.

I have been trying to read and write values to checkbox group elements in vain.

Please post here a functional code snippet that would select/deselect a checkbox called "beta" in a checkbox group called "alpha"

Thanks
GreyHead 16 Jun, 2012
Hi Lesanjo,

Sorry, I don't understand your question. Please explain with more details and perhaps an example.

Bob
Lesanjo 16 Jun, 2012
I want to detect which checkboxes in a group have been selected. I tried something like the following:
<?PHP
echo $form->data[alpha][beta];
?>

but I get;

* Uninitialized string offset

GreyHead 16 Jun, 2012
Hi Lesanjo,

If you temporarily add a debugger action you will see the full $form->data array.

For the values of the 'alpha' group try
<?php
echo $form->data['alpha'];
?>


You can't use 'beta' as a second key, it will be a value if it is selected.

Bob
Lesanjo 16 Jun, 2012
Thanks for the help. I have come across the following solutions.

1. In order to make a selection programmatically, ensure the custom code is set to controller, not view. then its as simple as...

$form->data[alpha]='beta';

2. For more flexible manipulation of predefined group checkboxes, is better to use PHP in_array to test the group form array

in_array('beta',$array)

Thanks again.
This topic is locked and no more replies can be posted.