Skip to content

Instantly share code, notes, and snippets.

@yellowstonebum
Last active September 15, 2018 18:17
Show Gist options
  • Save yellowstonebum/1c7ab326adf6763e9144891192abe7da to your computer and use it in GitHub Desktop.
Save yellowstonebum/1c7ab326adf6763e9144891192abe7da to your computer and use it in GitHub Desktop.
// Creating a chain select for a Gravity Forms List Field - https://docs.gravityforms.com/gf_field_list/
// TO-DO - Populate Column 3 "Company" with user display_names that have the role of 'company'
// 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_entries_column_filter', 'populate_complist', 10, 5 );
add_filter( 'gform_column_input', 'populate_complist', 10, 5 );
function populate_complist($value, $form_id, $field_id, $entry, $column, $query_string){
//only populating drop down for form id 7 - if editing this change to your own form ID
if($form["id"] != 42 && $field_id != 1)
return $value;
//Creating item array.
$items = array();
// 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
$metas = get_users( array( 'role' => 'company' ) );
if (is_array($metas))
{
// in this example we just load the display_name for each user into our drop-down field
foreach($metas as $meta) $items[] = array("value" => $meta->display_name, "text" => $meta->display_name);
}
//Adding items to field id 1. Replace 1 with your actual field id. You can get the field id by looking at the input name in the markup.
foreach($field->choices as $choice)
if($column == 'Company'){
$choices["text"] = $items;
}
return $value;
}
// TO-DO - javascript so that when the company column is changed, it repopulates the Feature Column
// TO-DO - Populate Column 4 "Feature" with Features that have matching companies with the seceted display_name companies
// TO-DO - javascript so that when the feature column is changed, it populates the details, address, phone number, cancellation, rarg() from the entry_id of the selected feature.
// TO-DO - Fields retain their ability to edited
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment