Last active
December 27, 2015 19:09
-
-
Save richardW8k/7375476 to your computer and use it in GitHub Desktop.
adds form active/inactive status switch to Gravity Forms form settings page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// display form active/inactive status on the form settings view | |
add_filter('gform_form_settings', 'form_settings_status', 10, 2); | |
function form_settings_status($settings, $form){ | |
$form_info = RGFormsModel::get_form($form["id"]); | |
$status_val = intval($form_info->is_active); | |
$status = $status_val ? __('Active', 'gravityforms') : __('Inactive', 'gravityforms'); | |
$settings["Form Basics"]["form_status"] = "<tr><th><label>Form status</label></th><td><img class='gform_active_icon' src='".GFCommon::get_base_url()."/images/active{$status_val}.png' style='cursor:pointer;margin:5px 0 0 0;float:left;' alt='{$status}' title='{$status}' onclick='ToggleActive( this, {$form["id"]} );' /> <span class='gform_status' style='margin:3px 0 0 10px;float:left;' >{$status}</span></td></tr>"; | |
return $settings; | |
} | |
// add script to settings page to allow toggling of active/inactive status | |
add_action('gform_admin_pre_render', 'pre_render_status'); | |
function pre_render_status($form){ | |
if (RGForms::is_gravity_page() && rgget('page') == 'gf_edit_forms' && rgget('view') == 'settings' && rgget('subview') == 'settings'){ | |
?> | |
<script type="text/javascript"> | |
function ToggleActive(img, form_id){ | |
var is_active = img.src.indexOf("active1.png") >=0 | |
if(is_active){ | |
img.src = img.src.replace("active1.png", "active0.png"); | |
jQuery(img).attr('title','<?php _e("Inactive", "gravityforms") ?>').attr('alt', '<?php _e("Inactive", "gravityforms") ?>'); | |
jQuery('span.gform_status').html('<?php _e("Inactive", "gravityforms") ?>'); | |
} | |
else{ | |
img.src = img.src.replace("active0.png", "active1.png"); | |
jQuery(img).attr('title','<?php _e("Active", "gravityforms") ?>').attr('alt', '<?php _e("Active", "gravityforms") ?>'); | |
jQuery('span.gform_status').html('<?php _e("Active", "gravityforms") ?>'); | |
} | |
var mysack = new sack("<?php echo admin_url("admin-ajax.php")?>" ); | |
mysack.execute = 1; | |
mysack.method = 'POST'; | |
mysack.setVar("action", "rg_update_form_active"); | |
mysack.setVar("rg_update_form_active", "<?php echo wp_create_nonce("rg_update_form_active") ?>"); | |
mysack.setVar("form_id", form_id); | |
mysack.setVar("is_active", is_active ? 0 : 1); | |
mysack.onError = function() { alert('<?php echo esc_js(__("Ajax error while updating form", "gravityforms")) ?>')}; | |
mysack.runAJAX(); | |
return true; | |
} | |
</script> | |
<?php | |
} | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment