marcq
Member
Hi,
I have created a calc element which calculate the end time of a sailing training session :
Involved fields :
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 :
Settings of the calc element :
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 :
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
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