Calc element woes [SOLVED]

liquid.ideas

New Member
Hi All,

Id really appreciate any advice, banging my head a bit here!

So what I have is a group with two checkbox elements in, multiple checkboxes. what I want it to do is count how many checkboxes are checked. I have managed this with all ajax cal and calc on load set to yes. If I do not use the ajax calc nothing happens, so here is the kicker it does not update the database although it displays right. If I take off ajax and calc on load it doesnt display right it displays "2". so here is a little more insight:
PHP:
$chbox = $data['drakensberg_gardens_9_repeat___gr_field1_raw'];
$chbox_count = 0;
if (!empty($chbox)) {
if (!is_array($chbox)) {
$chbox = json_decode($chbox, true);
}
$chbox_count1 = count($chbox);
}

$chbox = $data['drakensberg_gardens_9_repeat___gr_field2_raw'];
$chbox_count = 0;
if (!empty($chbox)) {
if (!is_array($chbox)) {
$chbox = json_decode($chbox, true);
}
$chbox_count2 = count($chbox);
}
return $chbox_count1 + $chbox_count2;
Thats the code I use, however the database score row (the calc element) always stays at "2" therefore I cant use that total to make other totals around the form!

I hope I have explained this well enough, any help would be much appreciated.
 
Hi Hugh,
Yep it is! - Edit: just moved it out and I have the same problem even if I put it in another group. If I check 1 box DB says NULL after saving, if I update it to where it should say 4 it still says NULL in DB and shows 0 on front end.
 
Edit #2: If I take it out the repeat group, thats actually ideally where I want it is out anyway I cant get it to calc at all
 
Here's the deal with the $data array and repeat groups in a calc.

If your calc is in a repeat, then the $data['yourtable_X_repeat___yourelement'] entries for that repeat group will be a single value, for the same instance of the repeat the calc being run is in.

For repeat groups that the calc is NOT in, the $data['yourtable_X_repeat___yourelement'] entries will be arrays, with as many entries as there are repeats.

So if your calc is not in the repeat, then ...

Code:
$chboxes=$data['drakensberg_gardens_9_repeat___gr_field1_raw'];

foreach ($chboxes as $chbox) {
   // now process $chbox as needed
}
 
Cheesegrits thanks so much! It does now indeed calculate outside the group, however its still storing in the database as null, do you know possibly why its not storing as a number? I need to be able to add up a few of these and Im a bit stumped!
 
Update: if I put the element back into the repeated group it saves into the database fine now. (huh??) so here we go... I need to use that total to sum up some other totals, so in a new group I have another calc element:Guest rooms total, and in that all I am doing is trying to repeat the calculated fuigure from before, it shows correctly but same issue its saving as NULL in DB, if I look at what Fabrik has created in the DB though, the new calc element just trying to return that value is sitting in the repeat table, is that correct? its wierd?
 
Let me mark this as closed, you heleped alot cheesegrits thanks with the above explanation, Im going to start again as it looks like there is stuff lying all over the database now and I want it freshened up!
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top