<?php
add_filter('gform_register_init_scripts', 'gf_script_custom_scripts');
function gf_script_custom_scripts($form) {
ob_start();
?>
(function($) {
$("li.gf_readonly input").attr("readonly","readonly");
});
})(jQuery);
<?php
$script = ob_get_clean();
GFFormDisplay::add_init_script($form['id'], 'gf_custom_scripts', GFFormDisplay::ON_PAGE_RENDER, $script);
return $form;
}
add_action("gform_pre_submission","pre_submission_handler");
function pre_submission_handler($form) {
// get input from form
$date = $_POST["input_1"]; // GF 'Date Picker' mm/dd/yyy
$starthour = $_POST["input_9"]; // GF "Drop Down' Hour Milittary Time
$startminute = $_POST["input_14"]; // GF "Drop Down' Minute Milittary Time
$endhour = $_POST["input_10"]; // GF "Drop Down' Hour Milittary Time
$endminute = $_POST["input_13"]; // GF "Drop Down' Minute Milittary Time
// convert date and time arrays into datetime formats
$startdate = new DateTime( $date . ' ' . $starthour . ':' . $startminute ) ;
$enddate = new DateTime( $date . ' ' . $endhour . ':' . $endminute ) ;
//convert datetimes into seconds to compare
$starttime = strtotime( $startdate->format( 'm/d/Y H:i' ) );
$endtime = strtotime( $enddate->format( 'm/d/Y H:i' ) );
// check to see if the times span overnight
if($starttime > $endtime)
$endtime = strtotime($enddate->format('m/d/Y H:i:s') . " +1 day");
// perform calculation
$diff = floor(($endtime - $starttime)/60/60);
$_POST["input_16"] = $diff;
}