Hi,
I have a rather simple question: In my form the user inputs to a textbox the duration of an activity in minutes, and I would like to store it in the DB table as hours. So simply to divide the user's input by 60 and preferably round it to 2 digits. Is there a simple way to do that? I tried to play a bit with JS code but but I'm not sure how to refer to the textbox, or change it.
Thanks!
I have a rather simple question: In my form the user inputs to a textbox the duration of an activity in minutes, and I would like to store it in the DB table as hours. So simply to divide the user's input by 60 and preferably round it to 2 digits. Is there a simple way to do that? I tried to play a bit with JS code but but I'm not sure how to refer to the textbox, or change it.
Thanks!
Hi Echo,
You can do this after the form is submitted with a little PHP (in the OnSubmit Before Email box in CFv3, or a Custom Code box in CFv4).
Bob
You can do this after the form is submitted with a little PHP (in the OnSubmit Before Email box in CFv3, or a Custom Code box in CFv4).
<?php
$minutes = JRequest::getInt('some_input_name', '', 'post');
$hours = '';
if ( $minutes ) {
$hours = round($minutes/60, 2);
}
// Uncomment the next line in CFv3
//JRequest::setVar('hours', $hours);
// Uncomment the next line in CFv4
//$form->data['hours'] = $hours;
?>
Bob
It works wonderfully. At first nothing changed but I noticed there was a missing ')' after the isset statement and that in last line I should have the same input name, so the working code is as follows:
Thanks bob, really appreciate your support 🙂
<?php
$minutes = JRequest::getInt('input_name', '', 'post');
$hours = '';
if ( $minutes ) {
$hours = round($minutes/60, 2);
}
if ( isset( $form->data )) {
$form->data['input_name'] = $hours;
}
?>
Thanks bob, really appreciate your support 🙂
This topic is locked and no more replies can be posted.