Using Gravity Forms ‘gform_quiz_show_choice_values’ PHP filter

The gform_quiz_show_choice_values Gravity Forms filter controls whether the values for the answer choices can be modified in the Form Editor. By default, the ability to set values is not available.

Usage

add_filter('gform_quiz_show_choice_values', 'gquiz_show_values');

Parameters

  • No parameters are required for this filter.

More information

See Gravity Forms Docs: gform_quiz_show_choice_values

Warning: Editing the values after entries have been submitted will affect the integrity of the results. Delete all entries for the form before editing the values.

Examples

Enable Answer Choice Value Modification

Enable the ability to modify answer choice values in the Form Editor.

add_filter('gform_quiz_show_choice_values', 'gquiz_show_values');

function gquiz_show_values() {
    // Enable answer choice value modification
    return true;
}

Disable Answer Choice Value Modification

Explicitly disable the ability to modify answer choice values in the Form Editor.

add_filter('gform_quiz_show_choice_values', 'gquiz_hide_values');

function gquiz_hide_values() {
    // Disable answer choice value modification
    return false;
}

Enable Answer Choice Value Modification for Specific Form

Enable the ability to modify answer choice values in the Form Editor only for a specific form with form ID 5.

add_filter('gform_quiz_show_choice_values', 'gquiz_show_values_specific_form', 10, 2);

function gquiz_show_values_specific_form($show_values, $form_id) {
    // Enable answer choice value modification for form ID 5
    return $form_id == 5 ? true : $show_values;
}

Enable Answer Choice Value Modification for Multiple Forms

Enable the ability to modify answer choice values in the Form Editor for multiple forms with form IDs 5, 7, and 10.

add_filter('gform_quiz_show_choice_values', 'gquiz_show_values_multiple_forms', 10, 2);

function gquiz_show_values_multiple_forms($show_values, $form_id) {
    // Enable answer choice value modification for form IDs 5, 7, and 10
    return in_array($form_id, [5, 7, 10]) ? true : $show_values;
}

Toggle Answer Choice Value Modification Based on User Role

Enable the ability to modify answer choice values in the Form Editor only for users with the ‘administrator’ role.

add_filter('gform_quiz_show_choice_values', 'gquiz_show_values_based_on_role', 10, 2);

function gquiz_show_values_based_on_role($show_values, $form_id) {
    // Get the current user
    $current_user = wp_get_current_user();

    // Enable answer choice value modification for administrators
    return in_array('administrator', $current_user->roles) ? true : $show_values;
}