[SOLVED] Calc Element | Erratic Calculation with custom bootstrap form template + SOLUTION

marcq

Member
Hi,

I have created a calc element which calculate the end time of a sailing training session :

Involved fields :
Code:
Duration : dropdown field : with the following values -> "3 heures", "5 heures" and "7 heures" values
Start time : dropdown field : with the following value -> "08:00", "08:30" and "09:00"
Landing time : calc element which return the landing time

For example : if "3 heures" and "08:00" the calc value returned should be "11:00", please see below the code of the calc element

Calculation :
Code:
$start = '{fab_booking___book_starttime}';
$matches = array();
if  (preg_match('/^(\d+)\s+/', '{fab_booking___book_termrental}', $matches)) {
    $duration = $matches[1];
   
    // var_dump($matches);exit;
   
if  (!empty($start)) {
    $end = new DateTime($start);
   
    // var_dump($duration);exit;

    return $end->modify("+" . $duration . " hours")->format("H:i");
   
}
else {
   return "";
}
}

Settings of the calc element :
Code:
Only Calc on Save = YES
Ajax calculation = YES
Ajax observe fields = '{fab_booking___book_starttime},{fab_booking___book_termrental}'
Calc on load = YES

Values calculated in the form are not always correct.

But, when I'm saving the form wrong values are always saved into the database field.

Code in the PHP Form Plugin :
Code:
$trainingendtime=$this->data['fab_booking___book_landingtime_raw'];
$trainingendtime = is_array($trainingendtime) ? $trainingendtime[0] : $trainingendtime;

// Update training endtime
$query = $db->getQuery(true);
$query = "UPDATE fab_booking SET book_landingtime = '$trainingendtime' WHERE id = '$bookingid'";
$db->setQuery($query);
$trip=$db->execute();

Debugging the form PHP plugin with var_dump ($trainingendtime) :

Duration value "3 heures" in combination with start time values ("08:00", "08:30" and "09:00") is returning wrong values when the form is saved :
08:00 with 3 heures -> "15:00", 08:30 with 3 heures -> "15:30", 09:00 with 3 heures -> "16:00"

But duration values "5 heures" and "7 heures" in combination with start values are always returning the correct values :
08:00 with 5 heures -> "13:00", 08:30 with 5 heures -> "13:30", 09:00 with 5 heures -> "14:00" etc.

Please see video.

http://www.screencast.com/t/92zx81JrS5

I have no clue where the problem could be. I have spent the whole day yesterday trying to solve this without success. So I would appreciate you help.

Thank you in advance. Cheers, marc
 
But your local time zone?
Not sure which day DateTime will use if you only set the hour.
Try to var_dump the complete end date.
 
I'm using the same calc element in another form and it is working fine. Correct value are saved in the table field.
All the settings regarding time zone are in both forms the same. In the first form which is working I'm using the standard bootstrap form template, in the second form a custom form template. I naturally try to set the template to bootstrap but no change.Server is in Paris and I m working in Asia., which means + 5 hours differences (utc Paris +2 utc bangkok +7). So when the calculation is rendering for start time 08:00 duration 3 hours 15:00 instead of 11:00 it don't seems to be a time zone issue, am I wrong?
 
Last edited:
One thing I don't understand is why you have a calc and a PHP plugin. I thought at first the PHP plugin was setting the end time on another table, but it seems to be the same table?

-- hugh
 
One thing I don't understand is why you have a calc and a PHP plugin. I thought at first the PHP plugin was setting the end time on another table, but it seems to be the same table?

-- hugh
Hi Hugh,

Thank you for the time. You right Hugh, why did I save the value with the php plugin since the calc element as a store in DB function? Stupid error of mine. Now it is working well... without the php plugin. Cheers, Marc
 
Yay! Glad it's fixed.
-- hugh

Hi Hugh,

Sorry to bother you again with this issue, but it seems that the problem remains when I'm using my custom frontend bootstrap form template. When I'm using the original bootstrap template the correct value is saved in the database.

Hereafter the code I'm using in my custom template :

Code:
$heuredebarquement = $elementsentrainement['book_landingtime']->element;

and

Code:
<td><div class="fabrikElementContainer"><?php echo $heuredebarquement; ?></div></td>

Can't find a solution after digging hours on this issue, would appreciate if you add a solution to this.

Thanks a lot in advance,

Cheers, marc
 
Try viewing the source of that DOM element, on both templates, and Spot The Difference. Elements not working in custom templates is almost always down to not reproducing the full structure, complete with the containing wrapped.
 
Try viewing the source of that DOM element, on both templates, and Spot The Difference. Elements not working in custom templates is almost always down to not reproducing the full structure, complete with the containing wrapped.
Hi Hugh,

Thanks for your reply. For your information, I have cloned the bootstrap form template to create my custom template.

Container is existing, picklists elements are for example wrapped (because they just don't work without), dropdown, fields are returning and saving the correct values without being wrapped, so it doesn't seems to exist a "unit? de doctrine".

Concerning the calc element which is returning and saving the correct value only with the original bootstrap form template, the calc is wrapped with the following :

Code:
<div class="controls">
   <div class="fabrikElement">
       11:30
   </div>
</div>

So I wrapped the calc element as followed in my custom form template :

Code:
<div class="controls"><div class="fabrikElement"><?php echo $heuredebarquement; ?></div></div>

or

Code:
<div class="controls"><div class="fabrikElementContainer"><?php echo $heuredebarquement; ?></div></div>

"fabrikElementContainer" because it is working for Picklist elements.

But it isn't working... Value is not saved.

I would appreciate a solution here, since I'm stuck and I've got about 10 forms with this calc element and a custom bootstrap form template.

Thank you in advance for your support.

Cheers, marc
 
Last edited:
Which site, and an example form/element to look at?

-- hugh
Hi Hugh,
You find all explanation about form, element etc. in "My Sites", please choose "LA NEPTUNE" and read the notes.

Last update : tried again different ways of wrapping the calc element in my custom template :

Code:
<div class="controls"><div class="fabrikElementContainer"><?php echo $heuredebarquement; ?></div></div>

or

<div class="controls"><div class="fabrikElement"><?php echo $heuredebarquement; ?></div></div>

or

<div class="fabrikElement"><?php echo $heuredebarquement; ?></div>

etc.

but nothing works. Saved value is always wong. Would appreciate a solution since my custom templates are useless...
 
Last edited:
Hi,
Is there a way how I could solve this issue ? Thank you in advance for you support, cheers, marc
 
Why are you still setting the trainingduration and other stuff in a PHP submission script?

Something weird is going on with the data. If you ...

var_dump($data);exit;

... at the start of the calc code, and display a form, you'll see stuff like this:

["fab_booking___book_termrental_raw"]=> array(1) { [0]=> string(1) "1" } ["fab_booking___book_termrental"]=> string(8) "7 heures"

... which is just wrong ... a raw of '1' should be '3 heures', not 7.

Are you sure this works with the standard template?

-- hugh
 
Why are you still setting the trainingduration and other stuff in a PHP submission script?

Something weird is going on with the data. If you ...

var_dump($data);exit;

... at the start of the calc code, and display a form, you'll see stuff like this:

["fab_booking___book_termrental_raw"]=> array(1) { [0]=> string(1) "1" } ["fab_booking___book_termrental"]=> string(8) "7 heures"

... which is just wrong ... a raw of '1' should be '3 heures', not 7.

Are you sure this works with the standard template?

-- hugh
Hi Hugh,

Thank you to have taken some time to look at this issue.

Yes your original bootstrap template is working, calc value is saved and updated correctly.

Please see the video : http://www.screencast.com/t/ZEdi5ifO

Concerning the PHP submission script, I have some code there because I would like my custom template being able to update the database fields. Without it, data are not updated.

If it is the wrong way to do it, I'm sorry ! But I couldn't find anything explaining how to do it and I thought it is the right way to do. Now I have disabled the php plugin of the form, data are not updated nor the calc value.

So the issue doesn't seems to have something to do with the calc element calculation.

Furthermore it seem that I have a problem with my custom template, since the original bootstrap template is saving the correct values among other the value of the calc element.

I am not a professional developer, I'm still learning. I'm not asking you to do the job for me, but just to point me in the right direction :

You seems to say that my custom template should save/update the form values without having to use the PHP plugin. I would appreciate if you could have a look at my custom template code (please see attached document custometemplate.txt) and just explaining me what I'm doing wrong.

If my question goes beyond what you are suppose to deliver to Professional Subscriber, please just tell me how much I have to pay to solve this issue and I will pay for it, since I need now to solve this issue.

Thank you in advance for you reply and your support.

Cheers, marc
 

Attachments

  • customtemplate.txt
    7.4 KB · Views: 169
Hi,
I don't want to rush, but I need support here, since the problem remains since weeks.
I'm ready if needed to extra pay to solve this issue.
Thank you in advance for your support.
Cheers, marc
 
Custom coding and templating doesn't come under subscription support, so we'd have to charge an hourly rate to work on it.

I've asked @mediaateam to contact you to discuss it.

-- hugh
 
Can you explain what the issue was for a) my curiosity, and b) the benefit of others who may have the same issue.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top