Home Forums Bug Reports acf_form failing after update


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

    <?php if (!strpos($_SERVER['REQUEST_URI'], '?thank-you')) : ?>
      <?php the_content(); ?>
      $fields = array( // Field groups
        '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" />'
    <?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

    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!

  • I can confirm having the same problem with this version.

  • 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:

    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.

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

The topic ‘acf_form failing after update’ is closed to new replies.