webaware

move Gravity Forms field labels from below to above fields

Aug 12th, 2013
534
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. * move field labels from below to above fields
  4. * add this to a simple plugin, or your theme's functions.php file
  5. *
  6. * @ref http://www.gravityhelp.com/forums/topic/change-position-of-sub-labels-on-advanced-fields
  7. * @ref http://pastebin.com/CfFeP4Ux
  8. *
  9. * @param array $form
  10. * @return array
  11. */
  12. function gf_script_move_labels_above($form) {
  13.     ob_start();
  14.     ?>
  15.  
  16.     (function($) {
  17.         $(".ginput_container").has("input[type='email'],input[type='text'],input[type='password'],select,textarea").find("label").each(function() {
  18.             var e = $(this), fielddesc = $("<div>").append(e.clone()).remove().html();
  19.             e.siblings("input,select,textarea").before(fielddesc);
  20.             e.remove();
  21.         });
  22.     })(jQuery);
  23.  
  24.     <?php
  25.     $script = ob_get_clean();
  26.     GFFormDisplay::add_init_script($form['id'], 'gf_labels_above', GFFormDisplay::ON_PAGE_RENDER, $script);
  27.  
  28.     return $form;
  29. }
  30.  
  31. add_filter('gform_register_init_scripts', 'gf_script_move_labels_above');
RAW Paste Data