SHOW:
|
|
- or go back to the newest paste.
| 1 | - | // for: http://www.gravityhelp.com/forums/topic/address-labels-below-fields#post-175408 |
| 1 | + | <?php |
| 2 | - | // copied from here: view-source:http://dev.calgunsfoundation.org/get-help/hotline/ |
| 2 | + | /** |
| 3 | - | // discussed here: http://stackoverflow.com/q/15490308 |
| 3 | + | * move field labels from below to above fields |
| 4 | - | // add the script below to an HTML block in your form |
| 4 | + | * add this to a simple plugin, or your theme's functions.php file |
| 5 | - | // corrected March 21, 2013 to properly handle email fields |
| 5 | + | * |
| 6 | - | // reference http://www.gravityhelp.com/forums/topic/change-position-of-sub-labels-on-advanced-fields?replies=13#post-177133 |
| 6 | + | * @ref http://www.gravityhelp.com/forums/topic/change-position-of-sub-labels-on-advanced-fields |
| 7 | - | // props DrDavid |
| 7 | + | * @ref http://pastebin.com/CfFeP4Ux |
| 8 | - | <script type="text/javascript"> |
| 8 | + | * |
| 9 | - | jQuery('.ginput_container label').each(function(i,e){
|
| 9 | + | * @param array $form |
| 10 | - | fielddesc = jQuery('<div>').append(jQuery(e).clone()).remove().html();
|
| 10 | + | * @return array |
| 11 | - | jQuery(e).siblings('.ginput_container input[type=email]').before(fielddesc);
|
| 11 | + | */ |
| 12 | - | jQuery(e).siblings('.ginput_container input:text').before(fielddesc); //moves sub label above input fields
|
| 12 | + | function gf_script_move_labels_above($form) {
|
| 13 | - | jQuery(e).siblings('.ginput_container select').before(fielddesc); //moves sub label above select fields (e.g. country drop-down)
|
| 13 | + | ob_start(); |
| 14 | - | jQuery(e).siblings('.ginput_container .gfield_radio input').after(fielddesc); //keep label above radio buttons
|
| 14 | + | ?> |
| 15 | - | jQuery(e).siblings('.ginput_container .gfield_checkbox input').after(fielddesc);
|
| 15 | + | |
| 16 | - | jQuery(e).remove(); |
| 16 | + | (function($) {
|
| 17 | - | }); |
| 17 | + | $(".ginput_container").has("input[type='email'],input[type='text'],input[type='password'],select,textarea").find("label").each(function() {
|
| 18 | - | </script> |
| 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'); |