Passing the setting of a Checkbox Group when calling the form

How to pre-set checkbox group selections when calling a ChronoForms form via URL.

Overview

The issue occurs because passing multiple checkbox values directly in the URL does not automatically populate the checkbox group fields.
To resolve this, add a Custom Code action in the form's On Load event to process the URL parameter. This code will convert the comma-separated values into an array that the checkbox group can recognize, allowing the specified checkboxes to be pre-selected.

Answered
Sk Skrodde 06 Sep, 2015
Hi everyone,
I have a form consisting of a TextBox "zip", a DropDownField "area", and three checkboxgroups "offers[]", "offers1[]", and "offers2[]". Calling the form via
?option=com_chronoforms5&chronoform=FORM-NAME&zip=CODE&area=OPTION

places the given CODE in the zip field and picks the given OPTION from the area dropdown. So far, so good. Now I would like to also pass on data as to which checkboxes in the three checkbox groups are checked.
How can this be accomplished?
Best, Skrodde
Gr GreyHead 06 Sep, 2015
1 Likes
Hi Skrodde,

It would help a lot if you explained what you need to do. There may be a simpler solutions.

If you need to call it from a URL including the checkbox values then you'd need to include a string of the values in the URL and then explode that in a similar way to your other post.

Bob
Sk Skrodde 06 Sep, 2015
Hi Bob,
thanks again for your fast answer. What I ultimately want to do is to call the form from somewhere else on my website. And depending from settings at that point, the form should have certain checkboxes pre-set (or not). That is, in my first checkboxgroup, called "offers", I have checkboxes "games", "talks", "entertainment". Ideally, I would like to call the form URL and add
&offers=games,entertainment

to have the "games" and the "entertainment" checkbox pre-set, but not the "talks" checkbox. I hope it's a little clearer now as to what I want to accomplish. I thought it has to be possible in a way like this, but I seem to be unable to get the syntax right. Could you maybe provide a MWE with the checkboxgroup "games" and the checkboxes "games", "talks", "entertainment"? That would be of tremendous help.
Best, Skrodde
Gr GreyHead 06 Sep, 2015
Answer
1 Likes
Hi Skrodde,

That will work OK. Like the other post you need to explode the values using a Custom Code action in the form On Load event
<?php
if ( !empty($form->data['offers'] ) ) { 
  $form->data['offers'] = explode(',', $form->data['offers']);
}
?>

Bob
Sk Skrodde 07 Sep, 2015
Hi Bob,
thanks again for the fast reply. All works fine now.
Best, Skrodde
This topic is locked and no more replies can be posted.