Checkboxes and event switcher

Use checkboxes with a ChronoForms event switcher.

Overview

The event switcher cannot directly compare an array from checkboxes to single values.
Replace the event switcher with an If Condition action that checks if a value is in the checkbox array, or use custom PHP code with the in_array function.

Answered
ChronoForms v6
pa pat01 12 Jul, 2019
Hi

I have two checkboxes:

Name: yourselection[]

Values:
0=AAA
1=BBB

And I have following action:

Event switcher
Data provider: {data:yourselection}
Events:
0
1

In both switches I have custom code.

But no matter what checkbox I tick, switching is not working.

Having both custom codes outside of the switcher = custom code is shown = custom code is OK.

The debugger shows following if checkbox 0 is ticked:
[yourselection] => Array
(
[0] => 0
)

and for checkbox 1:
[yourselection] => Array
(
[0] => 1
)

So values are passed.

What do I have to change to make the event switcher to work with checkboxes?

Thanks a lot!

Patrick
he healyhatman 12 Jul, 2019
Because yourselection[] is an ARRAY, not a single value. So yourselection will never equal 0 or 1, it will CONTAIN 0 or 1.

You need to use If Conditions instead, looking for your value being IN {data:yourselection}
he healyhatman 12 Jul, 2019
Answer
Although just now realising that Max made the IN condition wrong.

Just do it in PHP instead. Check if in_array(0, $this->data("checkboxesname"))
pa pat01 15 Jul, 2019
Thanks a lot, works fine!
This topic is locked and no more replies can be posted.