event switcher

How to conditionally show a dropdown based on multiple checkbox selections in ChronoForms.

Overview

The issue occurred because the user was incorrectly using the $form variable and shortcodes within PHP actions, which are not supported in CF8.
Replace all instances of $form with $this and use proper PHP syntax to access form data. Then, adjust the event switcher logic to correctly evaluate the checkbox selections and dynamically populate the dropdown options.

Answered
ChronoForms v8
kr kraadde 20 May, 2025

Max,

I have trouble solving one issue.

I have set php80 as follows:

$options = [

['value' => '{data:datum_1}', 'text' => '{data:datum_1}'],

['value' => '{data:datum_2}', 'text' => '{data:datum_2}']

];

return $options;

a checkboxes group datum_teiln with dynamic option set as {var:php80}

The field works as expected and allows the user to choose one or both options and store the [datum_teiln]

In case the user choose both options, I want to open a second dropdown form field for the user to select his preferred option.

For this, I have, before the event switcher, issued a php84 action as follow:

$selectedDates = explode(',', $form->data['datum_teiln']);

if (count($selectedDates) === 2) {

return 'hide'; // Event Switcher hides field

} else {

return 'show'; // Event Switcher shows field

}

In the 'show' event of the event switcher, I have another php82 action:

$options = [];

if (!empty($form->data['datum_teiln'])) {

$selectedDates = explode(',', $form->data['datum_teiln']);

if (count($selectedDates) === 2) {

// Dropdown show the selected dates

$options[] = ['value' => $selectedDates[0], 'text' => $selectedDates[0]];

$options[] = ['value' => $selectedDates[1], 'text' => $selectedDates[1]];

} else {

// in the case only one date is selected kepp it empty

return [];

}

}

return $options;

as well as the dropdown datum_vorz with the dynamic option set as {var:php82}

this is not working at all.

Can you suggest any solution?

Max_admin Max_admin 21 May, 2025
Answer

There is no $form variable in ChronoForms8, you should use $this

Also do NOT use shortcodes in PHP, example: {data:datum_2}, instead you should use PHP:

$this->data("datum_2")

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Post a Reply