Skip to content

Instantly share code, notes, and snippets.

@yellowstonebum
Created January 10, 2018 03:23
Show Gist options
  • Save yellowstonebum/e7af3e003fd8f2b8fdc48279d65540ef to your computer and use it in GitHub Desktop.
Save yellowstonebum/e7af3e003fd8f2b8fdc48279d65540ef to your computer and use it in GitHub Desktop.
Phone number dropdown
// This adds display names for all users to a drop down box on a gravity form.
add_filter("gform_pre_render", "populate_zone");
//Note: when changing drop down values, we also need to use the gform_admin_pre_render so that the right values are displayed when editing the entry.
add_filter("gform_admin_pre_render", "populate_zone");
function populate_zone($form){
//only populating drop down for form id 9 - if editing this change to your own form ID
if($form["id"] != 7)
return $form;
//Creating item array.
$items = array( 'text' => '', 'value' => '' );
// Get the custom field values stored in the array
// If editing this lookup where you would like to get your data from
// this example loads through all users of the website
$form_id = '2';
$entries = GFAPI::get_entries( 'formId=2&id=11' );
if (is_array($entries))
{
// in this example we just load the display_name for each user into our drop-down field
foreach($entries as $entry) $items[] = array("value" => $entry->display_name, "text" => $entry->display_name);
}
foreach($form["fields"] as &$field)
if($field["id"] == 7){
$field["choices"] = $items;
}
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment