Home › Forums › Bug Reports › acf_form failing after update
Hello!
I’m using a frontend form that was working until one of the last acf updates. Now getting an error: Undefined offset: 1 in ...\wp-content\plugins\advanced-custom-fields-pro\includes\api\api-helpers.php on line 4639
get_header();
acf_form_head();
...
<?php if (!strpos($_SERVER['REQUEST_URI'], '?thank-you')) : ?>
<?php the_content(); ?>
<?php
$fields = array( // Field groups
'field_5d0d0b6322401',
'field_5d0d0bbc22403',
'field_5d238bd5e3433'
);
acf_register_form(array(
'id' => 'new-cpt-name',
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'cpt-name',
'post_status' => 'draft',
),
'post_title' => false,
'post_content' => false,
'uploader' => 'basic',
'return' => get_the_permalink(get_the_ID()).'?thank-you',
'fields' => $fields,
'submit_value' => 'Submit your cpt-name',
'html_submit_button' => '<input type="submit" class="btn btn-primary" value="%s" />'
));
acf_form('new-cpt-name');
?>
<?php else : ?>
<h2>Thanks for submitting your request!</h2>
<p>A {...} website administrator will contact you within a week of your submission and provide a link to your custom {...}.</p>
<?php endif; ?>
Couple things I’ve tried:
1. Using output buffering around acf_form_head
ob_start();
get_header();
acf_form_head();
echo ob_get_clean();
2. Removing the server request conditional.
3. Another dev thought it may have to do with acf_validate_value()
within \wp-content\plugins\advanced-custom-fields-pro\includes\validation.php , but I could not quite see the issue there.
Confirmed that this is working with an older version of ACF (5.6.9 I believe).
Thanks for any help or suggestions with this one!
Good to know I’m not the only the one experiencing this–I thought I might be due to the lack of others submitting any kind of bug.
Do you have any guess as to what might be going on here, or have you tried any kind of workaround?
I had the same issue… Took me hours to figure it out. I can’t believe there’s no one else that has this problem…
I had put acf_register_form
right before the acf_form
call just like you based on a previous example that I had found. But after I updated ACF, this no longer worked.
I finally re-checked ACF’s documentation about how you’re supposed to set it up here: https://www.advancedcustomfields.com/resources/acf_register_form/#examples
Apparently you can no longer call acf_register_form
right before acf_form
. You need to call it via the acf/init
action and put that in your functions.php file. Do that and presto, it works again!
My guess is that it happened at version 5.8.5 back in October 2019 with this:
New – Optimized acf_form() logic when used in combination with acf_register_form().
Ah, you are right on. Such a headache. I could have sworn I checked the docs again at some point, but who knows–maybe they weren’t updated at that time.
Thanks much!
This has been a life-saver. Just to add to this – you dont even need to register the form in functions.php. Any code you previously had in the register function can simply be moved directly into the acf_form() function and it will work.
The topic ‘acf_form failing after update’ is closed to new replies.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.