Forums

Quick help with checkboxes group

wireframe 13 Feb, 2014
I have code which dynamically fills my checkboxes group below (based on a query which I did not include here): I have added a bit of code (in bold) to try and show these as "checked" but it is not working. How do I modify the code below to check off a checkbox in a group. I am going to use this with an if statement later and grab only checked off boxes for which the user has already checked off in a previous form. This form is a pre-loaded form with existing DB data. The field is a checkbox group and is dynamically loaded from a DB table. All I need is the proper code to access the "checked" value of a row.

$results = $db->loadObjectList();
foreach ($results as $row) :
$form->data['options'][] = array ('value' => $row->user_id, 'text' =>$row->name, 'checked'=>"checked");
endforeach;


Thank you in advance for your help.
Dawna
Max_admin 16 Feb, 2014
Hi Dawna,

Since this is a checkbox group, then the checked values are the ones inside an array passed under the $form->data array under the field name, so if your field name is "test" then the values below will be checked:


$form->data["test"] = array("val1", "val2");


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
wireframe 16 Feb, 2014
Thanks Max, that worked perfectly!

How about for a radio button? I need to show all available choices (all radios) but then the one which is selected from data coming in the query. When I use the code above, the only radio which shows is the one in the array, not all available ones. Different code?

Thanks again for great support!
Dawna
GreyHead 16 Feb, 2014
Hi Dawna,

I'm not clear whether you are talking about showing radio buttons or pre-checking them. If it's - pre-checking then $form->data['test'] = 'value'; should to it, only one radio button in a group can be checked.

Bob
wireframe 16 Feb, 2014
Hi Bob,

Yes, I was trying to check off (previously selected) radio buttons, but it wasn't working. I had a db multi-record loader with the same name so I think it was throwing things off. I changed the name of that and now it is working fine. For a while they kept disappearing completely, I think the code was getting confused with two arrays the same name.

Thanks for your help. It's all set now.
You guys are GREAT!
Dawna
This topic is locked and no more replies can be posted.