Home › Forums › General Issues › 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.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ποΈ Just one more day until the next session of ACF Chat Fridays! Make sure to register for the latest updates on whatβs coming in ACF 6.1!
— Advanced Custom Fields (@wp_acf) March 30, 2023
π Friday 31st March 3pm UTC
π Register here - https://t.co/3UtvQbDwNm pic.twitter.com/7xtEJakeQN
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.