New GF plug-in


SUBMITTED BY: Guest

DATE: Nov. 18, 2013, 5:28 a.m.

FORMAT: Text only

SIZE: 1.8 kB

HITS: 946

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

comments powered by Disqus