CF8 Run Conditions for Actions?

kgriffin 27 Jul, 2024

Hello-

I need to be able to trigger a save data action only if certain conditions are true from the form data (age of user is 18 or older). Chronoforms 7 has Run Conditions for this. What do I use for Chronoforms 8?

Max_admin 11 Aug, 2024

using a PHP events behavior, you do your conditions check using PHP code, check for data with $this->data("field_name"), variables with $this->get("var_name")

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
mgergel 14 Aug, 2024

Max- 

Can you be so kind as to elaborate on this? For example I have a custom PHP action that looks at a checkbox and returns T/F. How do I link that to my Save_Data10 action so that it only saves the data if the checkbox is checked? I see in the PHP an "Event" behavior is that what is used or something else. Thank you in advance for your time.

Max_admin 20 Aug, 2024

Hi mgergel

After you enable the Events behavior in PHP and define your events as T,F, save the form to rebuild the PHP action with events, then you can put your Save Data action in T event

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin 09 Nov, 2024
Answer

Run conditions added to v8.0.24

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
dct 03 Sep, 2025

Hi, I’m trying to use Run Conditions in the form’s onLoad section. Basically, with PHP I check whether a value exists in the DB and return a boolean. I was thinking of storing this value in a variable, as in this example:

...

$db->setQuery($query, 0, 1);

$exists = (bool) $db->loadResult();}

catch (\Throwable $e) {    // On any failure, keep $exists as false}

// Make the result available locally and to ChronoForm

$this->data("current_year_exists") = $exists;

// Fallback output when ChronoForm form object is not available

echo $exists    ? "LOAD COMPLETED FOR YEAR " . date('Y')    : "UPLOAD ENABLED FOR YEAR " . date('Y');

Right after the PHP action I want to use a Run Condition to show or hide a Container/Grid. But when I enter the variable name current_year_exists and the expected value, it doesn’t work. Where am I going wrong

CF8 Run Conditions for Actions? image 1

Max_admin 04 Sep, 2025

What is the value of the current_year_exists variable in the debug Vars array after your code runs ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
dct 08 Sep, 2025

Hi Max, the variable doesn’t show up in the debug, so it looks like it isn’t being instantiated.

The value I expect is 0/1, the same value stored in the $exists variable.

For simplicity, I created a test form with a simple PHP module in onLoad; the form does nothing other than this:

$exists = 1;

$this->data('current_year_exists', (int)$exists);

echo " | current_year_exists " . $this->data('current_year_exists') . " | exists " . $exists;

The output I’m getting is: | current_year_exists | exists 1.

Below is the debug screenshot.

CF8 Run Conditions for Actions? image 2

dct 09 Sep, 2025

Hi Max, I did some further digging and figured out why I couldn’t initialize the current_year_exists variable.

The assignment has to be done with 

$this->set("current_year_exists", $exists);

while reading uses

 $this->get('current_year_exists');.

With this approach, after my PHP block runs I can see the variable’s values in the debug

Vars

Array
(
    [app_active_page] => 1
    [current_year_exists] => 1
    [php2] => NULL
)

 but I still can’t get the Run Conditions to work, which I’ve defined as follows:

CF8 Run Conditions for Actions? image 3

Max_admin 11 Sep, 2025

Hi dct

Great, now you have to use {var:current_year_exists} to get the value of the var and use it in the comparison

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
You need to login to be able to post a reply.