Forums

Vacation Requests

trankin79 16 Sep, 2011
Hello!

I'm just starting out with Joomla and ChronoForms and am working on a vacation request form. I have it "working" but I wanted to do some calculations and auto-populate the total hours taken into a field. Based on the radio button they select, it populates the total hours ( 4 or 8 ) taken. But I need to count the days, times by the hours, then populate the total hours. Has anyone done this? Any help here would be great! I've added my code to the bottom.


<?php
// Get user-information from Joomla
$user = &JFactory::getUser();
?>
<input type="hidden" value="<?= $user->name; ?>" name="user" />
<input type="hidden" value="<?= $user->email; ?>" name="email" />
<div class="ccms_form_element cfdiv_datetime" id="start_date_container_div"><label>Start date</label><input maxlength="150" size="16" class="cf_date_picker" title="" type="text" value="" name="start" />
<div class="clear"></div><div id="error-message-start"></div></div><div class="ccms_form_element cfdiv_datetime" id="end_date_container_div"><label>End date</label><input maxlength="150" size="16" class="cf_date_picker" title="" type="text" value="" name="end" />
<div class="clear"></div><div id="error-message-end"></div></div><div class="ccms_form_element cfdiv_radio" id="time_frame_container_div"><label>Time Frame</label>
<input type="radio" name="radio" id="radio_am" title="" value="AM" onClick="javascript:document.getElementById('totalhours').value=4" class="validate['required']">
<label for="radio_am">AM</label>
<input type="radio" name="radio" id="radio_pm" title="" value="PM" onClick="javascript:document.getElementById('totalhours').value=4" class="validate['required']">
<label for="radio_pm">PM</label>
<input type="radio" name="radio" id="radio_all_day" title="" value="ALL DAY" onClick="javascript:document.getElementById('totalhours').value=8" class="validate['required']">
<label for="radio_all_day">ALL DAY</label>
<div class="clear"></div><div id="error-message-radio"></div></div><div class="ccms_form_element cfdiv_submit" id="input_submit_7_container_div"><input name="input_submit_7" class="" value="Submit" type="submit" />
<div class="clear"></div><div id="error-message-input_submit_7"></div></div><div class="ccms_form_element cfdiv_text" id="total_hours_container_div"><input maxlength="150" size="30" class="" title="" id="totalhours" type="hidden" value="" name="totalhours" /><div class="ccms_form_element cfdiv_text" id="number_of_working_days_container_div">
GreyHead 16 Sep, 2011
Hi trankin79,

If you don't need to display the results on the form itself I'd be inclined to do the calculations with PHP after the form is submitted. If your PHP is fairly up to date ( >= 5.3) there are some neat date-diff functions that make this much easier than handling dates in JavaScript.

Bob
trankin79 16 Sep, 2011
Very cool. I do not need to display it, just make sure it gets put in the DB. I guess I'm more confused on where to run the php, would it be an on submit function?
GreyHead 16 Sep, 2011
Hi trankin79,

You can drag a Custom Code action into the On Submit event for the form, drag it before the DB Save action and add the code there.

Bob
GreyHead 17 Sep, 2011
Hi trankin79,

In a Custom Code action in the On Submit event, before the DB Save action.

Bob
This topic is locked and no more replies can be posted.