Support

Account

Home Forums General Issues ACF & Gravity Forms Checkbox

Helping

ACF & Gravity Forms Checkbox

  • I am currently creating a website for a client that needs coaches pages. This is an example of a coach page. http://coaches.21daysugardetox.com/coaches/diane-sanfilippo/ I am currently using ACF for all the profile sections. The user can login and update the info from the frontend using the Gravity form add-on. The problem I am running into is with the checkboxes. When you hit submit on the form and go to update again the checkboxes are all back to being blank.

    I found this code that allows it to populate on the front end and save the previous selections.

    function my_acf_load_field( $field )
    {
        $field['choices'] = array(
            'athletes' => 'Athletes',
            'weight' => 'Weight Loss',
            'autoimmunity' => 'Autoimmunity',
            'pregnant' => 'Pregnant/New Moms',
            'diabetes' => 'Diabetes',
            'families' => 'Families',
            'corporate' => 'Corporate Wellness',
            'pescetarian' => 'Pescetarian',
            'large' => 'Large Groups',
            'small' => 'Small Groups',
            'coaching' => '1on1 Coaching'        
        );
    
        return $field;
    }
    
    // acf/load_field - filter for every field
    add_filter('acf/load_field', 'my_acf_load_field');
    
    // acf/load_field/type={$field_type} - filter for a specific field based on it's type
    add_filter('acf/load_field/type=select', 'my_acf_load_field');
    
    // acf/load_field/name={$field_name} - filter for a specific field based on it's name
    add_filter('acf/load_field/name=my_select', 'my_acf_load_field');
    
    // acf/load_field/key={$field_key} - filter for a specific field based on it's name
    add_filter('acf/load_field/key=field_550dee65fd2db', 'my_acf_load_field');

    The only problem here is the gravity form does not update the actual post on the backend to reflect these checkboxes.

    I did find this code that solves the gravity for issue.

    add_action("gform_after_submission_1", "acf_post_submission", 10, 2);
    
    function acf_post_submission ($entry, $form)
    {
       $post_id = $entry["post_id"];
       $values = get_post_custom_values("specialties", $post_id);
       update_field("field_550dee65fd2db", $values, $post_id);
    }

    The both fix the two issues I am having but they do not work when I have both of them in the functions.php . They only work when I comment one or the other out. Any suggestions?

    Thank You

  • Hi @cmoser,

    Thanks for the post.

    I am thinking that as a workaround you could pass the the new $field[‘choice’] values through the second acf_post_submission ($entry, $form) hook.

    This will allow you to create a and update the same values through the same function.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘ACF & Gravity Forms Checkbox’ is closed to new replies.