Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Last active May 1, 2020 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leepettijohn/ae354026b3d76f9ee41264d3198860e2 to your computer and use it in GitHub Desktop.
Save leepettijohn/ae354026b3d76f9ee41264d3198860e2 to your computer and use it in GitHub Desktop.
Gravity Forms - Pre-Populate List Field
<?php
/* Change form ID */
$location_form_id = 9;
add_filter( 'gform_pre_render_'.$location_form_id, 'populate_list' );
add_filter( 'gform_pre_validation_'.$location_form_id, 'populate_list' );
add_filter( 'gform_pre_submission_'.$location_form_id, 'populate_list' );
add_filter( 'gform_admin_pre_render_'.$location_form_id, 'populate_list' );
function populate_list( $form ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->label =='Add Field Label Here'){
$list_insertions[] = array('custom column name 1'=>'Column 1 Entry','custom column name 2'=>'Column 2 Entry');
}
$field->defaultValue = $list_insertions;
}
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment