How to write to {global:myfield}

update a global variable in ChronoForms.

Overview

Global variables in CF are read-only and cannot be modified directly.
Use a local form variable instead. Set the local variable to the global value, then update the local variable as needed within your form actions.

Answered
ChronoForms v7
Ed Eddi Bournell 20 Apr, 2024
In the Settings Manager of my Form I can use "Add Global Variable" to set a global variable manually. How can I set a {global:myfield}  in a php Action.?
Max_admin Max_admin 21 Apr, 2024
Answer
2 Likes
$this->globals("myfield")
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive teldrive 17 Feb, 2025

Hi Max

let me know why {global:local}  or {globals:local} show me the current value "1" in   html-box

and  in php-box  echo $this->global['local']; or echo $this->globals['local'];  doesn't show anything

kind regards

teldrive teldrive 17 Feb, 2025

sorry I already realized of my mistake echo $this->globals('local');    with round brackets ;-)

teldrive teldrive 17 Feb, 2025

Hi Max when Try to update global variable from my form I get this error

$this->globals('local')=2;

Captura de pantalla 2025-02-17 092705.png
Max_admin Max_admin 17 Feb, 2025

Hi teldrive

It's not possible to update the variables in the globals, you need to create a form variable and update it if you need:

$this->set("local", $this->globals("var"));

$this->get("local"); // this is how you get it now

$this->set("local", "new"); // now you can change it
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive teldrive 17 Feb, 2025

Hi Max

I must be missing something, I tried all this but I couldn't change the global variable from "1" to "2"

$this->set("local", $this->globals("local"));

$this->data['local']=$this->get("local");

echo $this->data['local'];

$this->set("local", "2");

echo "first attempt ".$this->globals("local");

$this->set( $this->globals("local"),"2");

echo "second attempt ".$this->globals("local");

$this->data['local']=2;

$this->set( $this->globals("local"),$this->data['local']);

echo "third attempt ".$this->globals("local");

thanks in advance

Max_admin Max_admin 17 Feb, 2025

The global variable can NOT be changed, you can only get it and use it 😉

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive teldrive 17 Feb, 2025

Ok , understood then you have to change the concept "global variable" by "global constant"😊

by the way should be very interesting to change it in order to avoid to create a table to make easier programming

Max_admin Max_admin 17 Feb, 2025

Yes, that would fit better 😊

But why did you need to change the global variable ? why not use a local variable ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive teldrive 17 Feb, 2025

I have an web-app to change plates database for an ANPR system, by default (for security reasons) web app only work with private IP address

If I need to test a new feature  remotely I change global variable to use IP public(only for administrator)  in a settings web page. Of course I can use settings table to do it, but I was exploring the possibility to use global variable to do it ;-)

Max_admin Max_admin 17 Feb, 2025

I think you can do this with a local variable at the form itself, but I can not imagine it well to try it

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Ed Eddi Bournell 07 Apr, 2025

Wehen I try : 

$this->set("local", $this->globals("var"));

I get an error : Call to undefined method G3\A\E\Chronoforms\L\Page::globals()

(CF7 , PHP 8.2, MariaDB 10.6)

Max_admin Max_admin 07 Apr, 2025

Where do you call it ? in a PHP action ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin Max_admin 07 Apr, 2025

which v7 version do you have installed ? and which Joomla ?

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