Can I pass a PHP variable from one 'box' to another

Pass a PHP variable between boxes in a ChronoForms form.

Overview

The user needed to store a calculated value from one form element for use in a later element.
Save the value to the CF data array in the first box, then reference it from that array in the subsequent box. Alternatively, consolidate the logic into a single custom code box to simplify the process.

Answered
fr fribse 23 Apr, 2016
Hi Guys

I'm slowly building a small calculation form.
I have an event switch in the output, where I do a small calculation in PHP.
Is it possible to save the result for use in a later 'box'? And how do I refer to the result later on?
Gr GreyHead 23 Apr, 2016
Hi fribse,

Save the result to the $form->data[''] array and then use that value later.

Bob
fr fribse 23 Apr, 2016
Hi Bob

I'm sorry, i'm not that experienced in PHP, could you spell it to me, how I do that?
I know it's probably basic, but that's me :-)
I've created a hidden field, which I guess I have to, to have a place to store it, correct?
Gr GreyHead 23 Apr, 2016
Answer
Hi fribse,

To make it more useful what do you actually have in your two boxes? What do you need to save and use later? And do you need to have two boxes rather than merging into one?

Bob
fr fribse 23 Apr, 2016
Ahh, you are absolutely right. Instead of using a complex set of 'event switch' and message boxes, and storing values, I could just use a custom code box, and put php in it with the switch in it, and all the calculations.
Much easier :-)
Now I just have to work on the multiplier thing, posted elsewhere, can't get my head around it...
Gr GreyHead 23 Apr, 2016
1 Likes
Hi fribse,

That sounds good, To answer the question, you can pass data between boxes by saving it like this in one box
<?php
. . .
$form->data['some_name'] = 'some_value';
?>
and then use it again later
<?php
switch ( $form->data['some_name'] ) {
 . . .
?> 

Bob
This topic is locked and no more replies can be posted.