Home Forums General Issues Where is the best place for updating hidden fields in acf_form()?


Where is the best place for updating hidden fields in acf_form()?

  • Previously I used ACF only in back-end & output fields in front-end with get_field(). I used acf-hooks. All was fine.

    But in the current project I use acf_form(). All my data are two types: for a user and for an admin. So, I separate them for “fields_group_admin” & “fields_group_user”. The user can edit content. The admin or PHP-code can edit “engine-data”, for example like terms of custom taxonomy “request_status”.

    THE ROOT OF THE PROBLEM with acf_form() + update_field():

    inside “acf/save_post”:
    update_field('_status', $status_term_obj->term_id, $post_id); // $value = 5


    $field_groups = array(
    'group_5729d360b78eb', // Request Admin Part is visible = all is work (I didn't touch admin-fields in front-end, fields were updated in my code in hook "acf/save_post" with priority 20!)
    'group_5729dc812096d', // Request User Part

    Don’t work:

    $field_groups = array(
    //'group_5729d360b78eb', // Request Admin Part is hidden = don't work!! (but, work field of User-type)
    'group_5729dc812096d', // Request User Part

    Please, look at the picture:
    On the top is “the working case”, on the bottom is “the not working case”. I changed just one string in code: I commented “Request Admin Part” and it’s hidden them in front-end.

    In the Debuger it looks that:
    1) start: – all is Ok
    2) inside: – the same
    3) updated: – but the “update reference” has $value=””
    4) “return != false”: – but:
    5) in wp-admin post is that: – don’t work!

    Looks like some a wrong updating of the field. I don’t understand why it is.

    The Questions:
    1) How must I properly hide admin\code-filds? (This fields I don’t show to users in front-end, but I need them in wpa-admin and for working site).
    2) How and where must I properly update admin\code-filds? Maybe “acf/save_post” not a good place for update_field() for the new acf_form() post.

  • At first:

    I must use keys, like “field_5729dc2c38f13”, instead names of fields.

    The solution for hidden in acf_form() fields (By “hidden” I mean that I don’t show it the field to user in front-end):

    update_field('_status', $status_term_obj->term_id, $post_id); // don't work
    update_field('field_5729dc2c38f13', $status_term_obj->term_id, $post_id); // work!

    I hope that will help someone.

  • At final I reject acf_form() because I don’t know how can I use it with hidden fields.

    I think ACF need the setting “Hidden in front-end: true/false” and the parameter acf_form() “input_init_values” => $init_values.

    For example, how must I do with acf_form():
    Question post about some item:
    1) item_id (hidden for user in front-end)
    2) title
    3) message

    Without acf_form() it will be:

    <form action="<?php echo get_stylesheet_directory_uri() ?>/question-update.php" method="POST">
    <input type="hidden" name="item_id" value="<?php echo get_the_ID() ?>" />
    <input type="text" name="title" value="" />
    <input type="textarea" name="message" value="" />
  • Hi @artfulcat

    I believe it’s because the database doesn’t have the reference key for the new custom field entries. This page should give you more idea about it (under the Basic (field key) section): To fix it, you need to use the field key instead of the field name like your solution.

    If you want to show certain the field groups or custom fields, I think you can use the “field_groups” and “fields” options. This page should give you more idea about it:

    I hope this helps 🙂

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

The topic ‘Where is the best place for updating hidden fields in acf_form()?’ is closed to new replies.