SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | ||
| 3 | add_filter('gform_register_init_scripts', 'gf_script_custom_scripts');
| |
| 4 | function gf_script_custom_scripts($form) {
| |
| 5 | ob_start(); | |
| 6 | ?> | |
| 7 | - | $date = $_POST["input_1"]; //GF 'date picker' using mm/dd/yyyy |
| 7 | + | |
| 8 | - | $start = $_POST["input_2"]; //GF 'timefield' using military time |
| 8 | + | (function($) {
|
| 9 | - | $end = $_POST["input_3"]; //GF 'timefield' using military time |
| 9 | + | $("li.gf_readonly input").attr("readonly","readonly");
|
| 10 | }); | |
| 11 | ||
| 12 | - | $startdate = new DateTime( $date . ' ' . $start[0] . ':' . $start[1] ) ; |
| 12 | + | })(jQuery); |
| 13 | ||
| 14 | - | $enddate = new DateTime( $date . ' ' . $end[0] . ':' . $end[1] ) ; |
| 14 | + | <?php |
| 15 | $script = ob_get_clean(); | |
| 16 | GFFormDisplay::add_init_script($form['id'], 'gf_custom_scripts', GFFormDisplay::ON_PAGE_RENDER, $script); | |
| 17 | ||
| 18 | return $form; | |
| 19 | } | |
| 20 | ||
| 21 | add_action("gform_pre_submission","pre_submission_handler");
| |
| 22 | function pre_submission_handler($form) {
| |
| 23 | // get input from form | |
| 24 | $date = $_POST["input_1"]; // GF 'Date Picker' mm/dd/yyy | |
| 25 | $starthour = $_POST["input_9"]; // GF "Drop Down' Hour Milittary Time | |
| 26 | $startminute = $_POST["input_14"]; // GF "Drop Down' Minute Milittary Time | |
| 27 | - | $_POST["input_7"] = $diff; |
| 27 | + | $endhour = $_POST["input_10"]; // GF "Drop Down' Hour Milittary Time |
| 28 | $endminute = $_POST["input_13"]; // GF "Drop Down' Minute Milittary Time | |
| 29 | ||
| 30 | // convert date and time arrays into datetime formats | |
| 31 | $startdate = new DateTime( $date . ' ' . $starthour . ':' . $startminute ) ; | |
| 32 | ||
| 33 | $enddate = new DateTime( $date . ' ' . $endhour . ':' . $endminute ) ; | |
| 34 | ||
| 35 | //convert datetimes into seconds to compare | |
| 36 | $starttime = strtotime( $startdate->format( 'm/d/Y H:i' ) ); | |
| 37 | $endtime = strtotime( $enddate->format( 'm/d/Y H:i' ) ); | |
| 38 | ||
| 39 | // check to see if the times span overnight | |
| 40 | if($starttime > $endtime) | |
| 41 | $endtime = strtotime($enddate->format('m/d/Y H:i:s') . " +1 day");
| |
| 42 | ||
| 43 | // perform calculation | |
| 44 | $diff = floor(($endtime - $starttime)/60/60); | |
| 45 | ||
| 46 | $_POST["input_16"] = $diff; | |
| 47 | } |