Support

Account

Home Forums General Issues Dynamically set form ID

Solving

Dynamically set form ID

    • Umeeshh

    • October 7, 2019 at 5:12 pm

    Hi, I’m working on website, where customer is allowed to create and save own custom posts on frontend. The problem is, edition should be possible within loop or at archive page – saved posts are custom post types – sizes of products. Customer can filter own sizes and edit them (in popup).

    I’ve put form inside loop, so the ID of form is ID or CPT post, but as it’s always the same form, there are same ID’s of fields and it won’t work this way I suppose 🙁

    Another way would be to put the form outside loop and set the ID of the form through jQuery when the edit button of post with particular ID was clicked.

    Any suggestion how to do that?
    Either use same form multiple times or dynamically set form ID through jQuery

    Thanks in advance for any suggestions 🙂

    • vverner

    • October 8, 2019 at 7:08 am

    Hey man!

    If you want to every post on page have it’s own form, you can do something like this in your acf_form() function:

    acf_form(array(
       'form_id' = 'form_' . get_the_ID(),
       'post_id' = get_the_ID()
       [...]
    ));

    Assuming that you are going to place that inside the loop like that

    while(have_posts()): the_post()

    P.s.: Sorry about my english

    • Umeeshh

    • October 9, 2019 at 12:40 am

    That’s how I’ve made it. But it won’t work 🙁
    This is my form:

    acf_form_head();

    $fields = array(
    ‘field_5d88ebc436c1d’, // s_body_size
    ‘field_5d88ec8636c1e’, // s_body_type
    ‘field_5d88ecc036c1f’ // s_head_size
    );
    acf_form(array(
    ‘id’ => ‘form-‘.$post->ID,
    ‘post_id’ => $post->ID,
    ‘new_post’ => array(
    ‘post_type’ => ‘custom_size’,
    ‘post_status’ => ‘publish’,
    ),
    ‘post_title’ => false,
    ‘post_content’ => false,
    ‘uploader’ => ‘basic’,
    ‘fields’ => $fields,
    ‘submit_value’ => ‘Update Size’
    ));

    Placed in loop ( while(have_posts()): the_post() )

    And it gives errors. Form itself has own ID, but inputs not. (Found 7 elements with non-unique id #acf-field_5d88ebc436c1d) as all fields of the form have same id’s

Viewing 3 posts - 1 through 3 (of 3 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.