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

But creating event switcher to check if valriable is existing or set has proven dificult to solve.I have tried
As well as {const:null} as event. Does NULL event exist in event switcher?
Aleksi
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"
Thanks.Do you mean something like this i found from FAQ.


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?
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"
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. :)
Great, you can clear a variable by setting it to null:
$this->set("session_id", null);
