Skip to content

Instantly share code, notes, and snippets.

@JayOkey
Last active January 27, 2019 11:08
Show Gist options
  • Select an option

  • Save JayOkey/849ffc1775b9993fb95ef6f60b634900 to your computer and use it in GitHub Desktop.

Select an option

Save JayOkey/849ffc1775b9993fb95ef6f60b634900 to your computer and use it in GitHub Desktop.
This plugin has been designed to copy the value of a checked Gravity Forms radio button if it has a class of lmd-copy to element with an id of lmd-paste.
<?php
/**
* Plugin Name: Launch Me Digital Gravity Copy Radio Value
* Plugin URI: https://launchmedigital.com
* Description: This plugin has been designed to copy the value of a checked Gravity Forms radio button if it has a class of lmd-copy to element with an id of lmd-paste.
* Version: 1.0
* Author: Jay Okey
* Author URI: https://launchmedigital.com
* Copyright: (c) 2018 Launch Me Digital
* License: GNU General Public License v2.0
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: lmd
*/
// Check if page has gravity form
function lmd_has_gform() {
global $post;
$all_content = get_the_content();
if ( strpos($all_content,'[gravityform') !== false ) {
return true;
}
return false;
}
// embed javascript that copies the selected fields value to another dom element
function lmd_gform_copy_radio_script() {
if (lmd_has_gform()) { ?>
<script>
jQuery(document).bind('gform_page_loaded', function(event, form_id, current_page) {
// code is trigged when next/previous page is loaded
var value = jQuery('.lmd-copy input[type=radio]:checked').val();
if(value) {
jQuery('#lmd-paste').text(value.split('|')[0]);
}
});
</script>
<?php
}
}
add_action('fl_body_close', 'lmd_gform_copy_radio_script');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment