Gform predefined choices

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");

Examples

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;
}
?>

This example adds a new predefined choice incorporating choices that have a value that is different than the choice label.

<?php

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

Source Code

This filter is located in form_detail.php

Search the Documentation