Event Switcher Null event

How to check if a CF variable is null or empty using an event switcher.

Overview

The Event Switcher action cannot directly evaluate a null or unset variable to trigger different events.
Use a PHP action with the Events behavior to check the variable's value and return a specific event name, such as 'SetID' or 'HasID', based on the condition.

Answered
ChronoForms v8
al aleksinverstas332 29 Oct, 2025

I need to check if variable {var:session_id} has a value on it and if not to set it.Setting is easy. 

Event Switcher Null event image 1

But creating event switcher to check if valriable is existing or set has proven dificult to solve.I have tried Event Switcher Null event image 2 

As well as {const:null} as event. Does NULL event exist in event switcher?

Aleksi

Max_admin Max_admin 29 Oct, 2025
Answer

Hi Aleksi

You can use a PHP action with the Events behavior, that's equivalent to event switcher but with PHP code, this way you can check the NULL condition and return a different string for the event name.

Or, if you want to use the Event Switcher, then set a default value for the variable at the start of the form, like "0"

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
al aleksinverstas332 29 Oct, 2025

Thanks.Do you mean something like this i found from FAQ.

Event Switcher Null event image 3

Event Switcher Null event image 4

If i use $this->data("session_id", ""); it runs but does not see value i variable.

If i use $this->var("session_id", ""); it stops in error.

So how i should refer to chronoforms variable from php?

Max_admin Max_admin 30 Oct, 2025
1 Likes

Hi Aleksi

The PHP action has Events behavior, your PHP code can be like this:

if($this->get("session_id", "") != ""){
return "set";
}else{
return "not";
}

and add 2 events, "set" and "not"

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
al aleksinverstas332 31 Oct, 2025

Thanks for the quidance.That did not quite work as unset variable would be see null but it guided me in right way.This worked perfectly.

$session_id = $this->get("session_id");

if( $session_id == "" or $session_id == null or $session_id == "Kiitos"){
    return "SetID";
}else{
    return "HasID";
}

Clearing variable at the end of the process proved to be challenging so just acknowledge that with "Kiitos" at the end of the process if one user wants to have another go.

Not pretty but works. :)

Max_admin Max_admin 31 Oct, 2025
1 Likes

Great, you can clear a variable by setting it to null:

$this->set("session_id", null);
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Post a Reply