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


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.

  • thank you, this was exactly what I was looking for and it answered my question.

    I’m using Oxygen Builder so i dont have access to the header.php or theme pages which made me put the acf_form_head() in the functions.php file and the init hook callback works like a charm!

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

You must be logged in to reply to this topic.