Calculating Total from Repeat elements

mamies

Member
Hi All,

I have a group in which I have repeat fields.

I would like to be able to calculate the total of the repeat fields for each specific entry. Some entries may have 1 field but others may have up to 14.

Thanks,
 
Sorry,

I should have replied. I worked it out. It appears that I was using the wrong field resulting in no value.

I used a form plugin (PHP) and ran it OnBeforeStore.

Code:
$elementarray = $formModel->formData['data_repeat_table___element'];
$elementsum = array_sum($itemcostget);
$formModel->updateFormData('data_table___calculation', $elementsum, true);
 
unfortunately the site is sitting behind in an intranet without access to the internet which will screw that idea up.

If you put your elements and table names here I can help with the script and where to put it.
 
Create a new plugin under form:
  • --do-- = php
  • In = Both
  • On = Both
  • Process Script = OnBeforeStore
PHP Code will be (a little unsure on the calculation field so I have called it jie_pedidios___calculation but you will need to change below).
Code:
$vtotalarray = $formModel->formData['jie_pedidos_18_repeat___v_total'];
$vtotalsum = array_sum($vtotalarray);
$formModel->updateFormData('jie_pedidos___calculation', $vtotalsum, true);

Also change the Repeat Total Calc field to use the field plugin with decimal chosen under formatting. Also select Yes for Hidden under options.

Thanks,
 
does using the following in the plugin output the correct amount
Code:
$vtotalarray = $formModel->formData['jie_pedidos_18_repeat___v_total'];
$vtotalsum = array_sum($vtotalarray);
echo "<pre>";print_r($vtotalsum);exit;
$formModel->updateFormData('jie_pedidos___calculation', $vtotalsum, true);
 
try
Code:
$vtotalarray = $formModel->formData['jie_pedidos_18_repeat___v_total'];
$vtotalsum = array_sum($vtotalarray);
echo "<pre>";print_r($vtotalarray);exit;
$formModel->updateFormData('jie_pedidos___calculation', $vtotalsum, true);
[/quote]
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top