Skip to content

Instantly share code, notes, and snippets.

@webaware
Created May 12, 2014 03:39
Show Gist options
  • Select an option

  • Save webaware/24e1bacb47b76a6aee7f to your computer and use it in GitHub Desktop.

Select an option

Save webaware/24e1bacb47b76a6aee7f to your computer and use it in GitHub Desktop.

Revisions

  1. webaware revised this gist May 12, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gravity-forms-fields-above.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    <?php
    /*
    Plugin Name: Gravity Forms Fields Above
    Plugin URI:
    Plugin URI: https://gist.github.com/webaware/24e1bacb47b76a6aee7f
    Description: move field labels from below to above fields in compound fields (e.g. Address, Name)
    Version: 1
    Author: WebAware
  2. webaware created this gist May 12, 2014.
    46 changes: 46 additions & 0 deletions gravity-forms-fields-above.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    <?php
    /*
    Plugin Name: Gravity Forms Fields Above
    Plugin URI:
    Description: move field labels from below to above fields in compound fields (e.g. Address, Name)
    Version: 1
    Author: WebAware
    Author URI: http://webaware.com.au/
    @link http://www.gravityhelp.com/forums/topic/change-position-of-sub-labels-on-advanced-fields
    @link http://pastebin.com/CfFeP4Ux
    @link http://pastebin.com/WCuDc0Eh
    */

    /**
    * make sure jQuery is loaded
    */
    add_action('wp_enqueue_scripts', function() {
    wp_enqueue_script('jquery');
    });


    /**
    * register custom form scripts
    * @param array $form
    * @return array
    */
    add_filter('gform_register_init_scripts', function($form) {
    ob_start();
    ?>

    jQuery(".ginput_container").has("input[type='email'],input[type='text'],input[type='password'],select,textarea").find("label").each(function() {
    var e = jQuery(this), fielddesc = jQuery("<div>").append(e.clone()).remove().html();
    e.siblings("input,select,textarea").before(fielddesc);
    e.remove();
    });

    <?php
    $script = ob_get_clean();

    GFFormDisplay::add_init_script($form['id'], 'gravity-forms-fields-above', GFFormDisplay::ON_PAGE_RENDER, $script);

    return $form;

    });