Support

Account

Home Forums Feedback acf_form() – not saving repeater's data

Helping

acf_form() – not saving repeater's data

  • Hi everyone,

    This is not a question, just want to help anyone who is struggling with the same issue I just spent 6+ hours debugging to solve. Perhaps someone from the team of excellent people who develop this plugin might find it useful to be included in the official documentation. 🙂

    tl;dr If you are not calling acf_form_head() in the template file (as is in the documentation example), but somewhere in your theme’s function.php or in the plugin files, make sure you wrap it in an init hook callback, otherwise some unexpected things might happen.

    The context: I have created an admin page (probably not that relevant) for a plugin, and was calling acf_form_head() somewhere in the main plugin php file, with a check for $_GET['page'] to match the slug of my page. On the template for my custom page I have called acf_form() with args, and everything seemed fine. I was able to submit some basic fields, text, image, even taxonomy terms… but repeaters? Nope. When I submit any data, all repeaters are deleted. Only repeaters.

    I tried to save the same field group through the native form, everything worked. I started debugging and found out that when submitting through the acf_form() generated form, filter acf/update_value/type=repeater is not triggered in acf-value-functions.php:188, while it is triggered when I submit it through the normal acf form. Everything else worked fine…

    Long story short, inspecting the context and available classes, I found out that the class acf_field_repeater was not available at all. Then I found out that acf_form_head() doesn’t only enqueue the scripts/css, but also does the form processing, and it matters very much when it is called. So I put it into the init hook callback, and everything worked properly.

  • This is part of the documentation, not spelled out exact terms, but that is what this means:

    … To allow the form to save data, you will need to place the acf_form_head() function at the top of your page template before any HTML is rendered.

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

You must be logged in to reply to this topic.

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.