how to sum a total for repeat group ......

solomon2773

New Member
I am trying to sum a total value for a repeat group. I have two groups in a form. First group is a repeat group, and second one is a non-repeat group. Currently the repeat only have one element which is field element and user can repeat it at front end and enter int value. Second group only has one calc element with the code shown below.
When i click on save, i can only read out a value from row 0 from the repeat group. Would you please help on this? Or Can i use this in a multi page form?
Setting up group 3 as second page and only have one element reading the sum value from group2 of page1? Is this possible?

Code:
$test1 = explode(',', "{ez12_package_forward_order_270_repeat___test1}");

$total = array();
for ($i=0; $i < count($test1); $i++) {
  $total[$i] = $test1[$i];
}
$sum = array_sum($total);
return $sum;
 
rather than using the placeholder you would need to access the $_POST request data.

So add this:

PHP:
$post = JRequest::get('post');
echo "<pre>";print_r($post);exit;

to see what the data structure is of the form's posted data.

You should see a nested array

['join'][{yourjoinsid}]['z12_package_forward_order_270_repeat___test1']

which itself is an array of the submitted repeat values.

So replace you $test1 with the data found there

-Rob
 
i will try it tonight. Will this work on multi page form? i am trying to get the data that customer select on first page and when ever they click "next" the calc field will sum the total price of their selections and showing on page2 with some calculation.
 
Hi Solomon2773,

Did you ever get this to work? Can you please post your solution here? I'm trying to do a similar thing. To sum a single element in a repeating group. I did what Rob said about getting my $_POST request data, but it doesn't look like what Rob posted as a sample. I can't get your code to work, at least so far.

Thanks,
Railer
 
Hi

"something similar" - in which way, as part of a final form submission or as a javascript calculation when moving between multipage form groups?
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top