Buy Now
Sign in

Repeater area load input

peppelaria , April 18 at 19:42
Answered
peppelaria
Hi Max. I'm using chronoforms 6 and i'm facing a problem with repeater area.
I Just created a repeater area with inputs and I already managed to set it up and save te values in json format.
What is the best way to load json and populate the repeater inputs from read_data in order to edit saved data?
peppelaria
Hi Max; I just figured it out how to get my form working.
Chronoforms 6 is really fantastic.
GreyHead
Hi peppelaria,
Well done - please can you post the solution you found as that will help other users (including me).
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
peppelaria
Hi Bob. below the solution.

In the “found event” of “read_data” put a php to decode json saved before looping repeater area input.

The json format looks like: “[{"installment":"1000"},{"installment":"200"},{"installment":"300"}]

Below is the php code use to decode and loop:

$installments_array = array();​
​​
​$jsondec = json_decode($this->get("read_data7.Product.installments"), true);​
​​
​$i = 0;​
​foreach ($jsondec as $json) {​
​ $a = $json['installment'];​
​ $installments_array["installments[".$i."][installment]"] = $a;​
​ $i++;​
​}​
​​
​$this->data("installments_array", $installments_array, true);

once the array is filled, put “{data:installments_array}” in the data provider of repeater area and “{var:area_repeater_name.row}” in the data provider of the text field and that’s it.

The repeater will instantiate as many text field as the array elements number filed up with respective values