In the example:

  • I have an ID 3 form
  • Not my champion ID 4
  • Should autofill with field value acf  field_5edf1b7c5e574

Hooks Gravity Form

add_filter( 'gform_pre_render_3', 'function_name' ); //_3 is the form ID
add_filter( 'gform_pre_validation_3', 'function_name' ); //_3 is the form ID
add_filter( 'gform_pre_submission_filter_3', 'function_name' ); //_3 is the form ID
add_filter( 'gform_admin_pre_render_3', 'function_name' ); //_3 is the form ID

function function_name( $form ) {
foreach ( $form['fields'] as &$field ) {

if( $field['id'] == 4 ) { //ID of Gravity field

$acf_field_key = "field_5edf1b7c5e574"; //identifier of the ACF field (right click > inspect to get it)
$acf_field = get_field_object($acf_field_key);
$choices = array(); // Set up blank array

if( $acf_field ) {

foreach( $acf_field['choices'] as $k => $v ) {
$choices[] = array( 'text' => $v, 'value' => $k );
}
}

$field->placeholder = '-- Select --'; //optional, allows to display a text for the selection (option 0)

$field->choices = $choices;

}
}
return $form;
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Commentaires
Inline Feedbacks
View all comments