PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Using the Gform predefined choices filter

  1. Our new documentation should be rolling out soon, but for now, here's the details on how to use the Gform predefined choices filter to create new predefined choices for multiple choice fields, checkboxes and drop-down fields.

    Description
    ________________________________________

    This filter is executed when the form editor is loaded, before creating the list of predefined choices for the selection fields (Checkboxes, Multiple Choice and Drop Down). This hook can be used to add new predefined choices as well as deleting existing ones.

    Usage
    ________________________________________

    Applies to all forms

    <?php
    add_filter("gform_predefined_choices", "add_predefined_choice");
    ?>

    Applies to a specific form. In this case, form Id 5

    <?php
    add_filter("gform_predefined_choices_5", "add_predefined_choice");
    ?>

    Parameters
    ________________________________________

    $choices
    (Array) An array with the existing predefined choices to be filtered. It is an associative array where the key is the title and the value is an array containing the choices.

    $choices["My Favorite Food"] = array("Fruit", "Hamburger", "Beans");

    Example
    ________________________________________

    This example adds a new predefined choice to the end of the list.

    <?php
    
    add_filter("gform_predefined_choices", "add_predefined_choice");
    function add_predefined_choice($choices){
       $choices["My New Choice"] = array("Choice 1", "Choice 2", "Choice 3");
       return $choices;
    }
    ?>

    Source Code
    ________________________________________

    This filter is located in form_detail.php

    Posted 13 years ago on Friday January 7, 2011 | Permalink