Forums

Calculation of fields in Chronoforms7

jevago 25 Sep, 2022
My first post on this forum.
I'm currently working on a migration of Joomla 3 towards Joomla 4. On Joomla 3 I used Breezingforms, but since its not developed anymore I am looking for an alternative so I came to ChronoForms.

I've recreated my form but there are a couple of things which I am not able to get it working on ChronoForms. For example, I use calculation on fields in the form.

In breezingforms I used the following;
function ff_fd_volwassenen_action(element, action)
{
ff_getElementByName('fd_bedrag').value =
Number(ff_getElementByName('fd_volwassenen').value) * 24 +
Number(ff_getElementByName('fd_kinderen').value) * 15;
}
// ff_fd_volwassenen_action

Basicly it get the input of 2 fields, multiply it and sum it to a total.

Is this possible to get it working on ChronoForms?
GreyHead 07 Oct, 2022
Hi jevago,

if you use the Advanced form type then there are Actions available where you can add Custom PHP or JavaScript to do tasks like this.

Bob
Colnem 08 Oct, 2022
IN a PHP Action use this:

To get a CF7 variable {var:my_var} in a PHP variable:
$varPhp1=$this->get("cf7_var", "");

To get a CF7 data {data:my_data] in a PHP variable:
$varPhp2=$this->data("data_field_name", default_value);
default_value may be 0 (numeric), "" (string), [ ] (array), ...

So you can use php o calculate, like this, for example
$varPhp3= $varPhp1 + 15 *$varPhp2;

Then to set a var CF7 with the result:
$this->set("cf7_var", $varPhp3);

To set a data CF7 with the result:
$this->data("data_field_name", $varPhp3,true);
You need to login to be able to post a reply.