How do I pre select multiple checkboxes in a group

How to pre-select multiple checkboxes in a ChronoForms checkbox group.

Overview

The issue occurs because the form designer's "selected values" field does not accept comma-separated values for multiple selections.
Add a Custom Code action before the Render Form action to programmatically set the checkbox group's data as an array containing the desired values.

Answered
pe pete 08 Mar, 2015
Hi,
In Designer mode, I have a checkbox group with options
fn_1=description_1
fn_2=description_2
....
fn_n=description_n

and selected values fn_1,fn_2 etc

When the form is displayed in Designer mode with only one entry in selected values (e.g. fn_1) it correctly displays the selected checkbox.

If I add a second comma separated value (e.g. fn_1,fn_2), then nothing is shown as selected. (I have also tried space and semicolon).

Could anyone let me know how this should be done as I can't find this documentsed anywhere (or I have missed it!)

Thanks
Pete
Gr GreyHead 09 Mar, 2015
Answer
Hi Pete,

I don't think that you can set a multiple selection that way :-(

I've never seen the question asked before but I would try to solve it by adding code like this to a Custom Code action in the form On Load event:
<?php
if ( !isset($form->data['checkbox_group_name']) || !is_array($form->data['checkbox_group_name']) ) {
  $form->data['checkbox_group_name'] = array('fn-1', 'fn_2');
}
?>

Bob
pe pete 09 Mar, 2015
Hi Bob
I have added the following to a custom code and not sure whether it should go before or after the render.


<?php
if ( !isset($form->data['checkbox'] ||  
     !is_array($form->data['checkbox']) ) {
   $form->data['checkbox'] = array('advice_socialisation', 'advice_socialisation_check');
}
?>


Either before or after, it gives an error on form load of...

Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR), expecting ',' or ')' in /home/superpan/public_html/...../custom_code.php(20) : eval()'d code on line 2

[attachment=0]one.png[/attachment]
[attachment=1]two.png[/attachment]
[attachment=2]three.png[/attachment]
[attachment=3]four.png[/attachment]

Thanks...
Pete
Gr GreyHead 10 Mar, 2015
Hi Pete,

Sorry, I missed a bracket ) in line 2 - fixed now.

It would go in a Custom Code action before the HTML (Render Form) action.

Bob
pe pete 10 Mar, 2015
I checked for that but missed it! Amateur!

Yet again, many thanks Bob, that worked perfectly.

Now just need the attachment problem sorted - LOL
This topic is locked and no more replies can be posted.