Last active
May 1, 2020 15:56
-
-
Save leepettijohn/ae354026b3d76f9ee41264d3198860e2 to your computer and use it in GitHub Desktop.
Gravity Forms - Pre-Populate List Field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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