Support

Account

Home Forums Front-end Issues Pre-Populate GF form with ACF Field Data Reply To: Pre-Populate GF form with ACF Field Data

  • If all of your fields in GF have the same field name as the field names in ACF then there is a way that you can use a single function, that’s if I’m understanding the GF hook from what I’m seeing.

    I’m assuming that the GF hook is "gform_field_value_{$your_field_name}"

    Lets say you have 2 fields

    
    $field_names = array('field_1', 'field_2');
    foreach ($field_names as $name) {
      add_filter('gform_field_value_'.$name, 'load_my_custom_values');
    }
    function load_my_custom_values($value) {
      // get the current filter that was called
      // it will contain the field name
      $filter = current_filter();
      // remove 'gform_field_value_' from filter name
      $field = str_replace('gform_field_value_', '', $filter);
      $id = get_current_user_id();
      $post_id = 'user_'.$id;
      $value = get_field($field, $post_id);
      return $value;
    }