• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

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