-
-
Save version-control/55031eebf283a3901e6b1e67fd009e2f to your computer and use it in GitHub Desktop.
Gravity Forms - Limit checkbox choices after chosen
This file contains hidden or 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
<? | |
// Change 'XXX' to your form id | |
$location_form_id = XXX; | |
add_filter( 'gform_pre_render_'.$location_form_id, 'limit_choices' ); | |
add_filter( 'gform_pre_validation_'.$location_form_id, 'limit_choices' ); | |
add_filter( 'gform_pre_submission_'.$location_form_id, 'limit_choices' ); | |
add_filter( 'gform_pre_submission_filter_'.$location_form_id, 'limit_choices' ); | |
add_filter( 'gform_admin_pre_render_'.$location_form_id, 'limit_choices' ); | |
function limit_choices( $form ) { | |
global $wpdb; | |
$tablename = $wpdb->prefix . 'rg_lead_detail'; | |
$jquerylimits = array(); | |
foreach ( $form['fields'] as &$field ) { | |
if ( $field->id == xxx) { | |
foreach ($field->inputs as $eachchoice){ | |
$sqlquery = "SELECT id FROM $tablename WHERE form_id=".$form['id']." AND FORMAT (field_number,3) = FORMAT(".$eachchoice['id'].",3) ORDER BY lead_id"; | |
$values = $wpdb->get_var($sqlquery); | |
if (!empty($values)){ | |
$jquerylimits[]='$(\'input[name="input_'.$eachchoice['id'].'"]\').attr("disabled","disabled");'; | |
} | |
} | |
print_r('<script>jQuery(document).ready(function($){'); | |
foreach ($jquerylimits as $eachlimit){ | |
print_r($eachlimit); | |
} | |
print_r('});</script>'); | |
} | |
} | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment