• Resolved pankamilr

    (@gordon34)


    Hi all,
    i created a form using ACFE and put as an action ‘Custom Action’. Then I add shortcode to my page and the form was rendered. I fill the form, press “Submit”, handle data with ‘acfe/form/submit/action-name’ hook and save to DB using ‘update_field’. It’s saved. But when I refresh the page in frontend I don’t see any saved entries. What i’m doing wrong?

    • This topic was modified 3 years ago by pankamilr.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter pankamilr

    (@gordon34)

    I see that no one want’s to help me so maybe I will extend my question, maybe Author will read it again ??

    I use “Form” from ACFE to create a form based on field group and I put [acfe_form name="some-name"] in template file and form was printed correctly. I filled the form with some data and submit the form. I’m handling form data with action hook acfe/form/submit/some-name and save data to the database with update_field function. It worked as supposed. Database was updated. Then I refresh the page with form and… the form is empty. Why form was not pre-filled with saved DB values?

    I did some debugging and take a look how this forms are rendered and i found acfe_form_front::render_form($args) method and inside this method is called $this->render_fields($args, $fields) method and finally inside this method is done acf_render_fields function (acf core function) where second parameter should be $post_id defining ID of the post where the form is rendered BUT instead of ID of a post there is provided some acf_uniqid('acfe_form') value which don’t know how it’s connected to the post and I assume that’s why values aren’t loaded in form.

    Can Author describe me how this should work and why/how values aren’t/should load to the form. I really need to know ?? Thank you in advance

    • This reply was modified 3 years ago by pankamilr.
    Thread Starter pankamilr

    (@gordon34)

    Ok it turns out that when I add action called Post action then I saw how is it working but IMO it’s a bit misleading. What is the purpose of using Custom action hook when values aren’t loaded back to the form? I can load them when I use Post action -> Load tab.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    Yes, it’s the weekend, so all my time is dedicated to the plugin development ??

    I’m glad to hear you managed to make it work! In fact, the Custom Action doesn’t handle value preloading, you’ll have to handle that part using the acfe/form/load PHP hook (See documentation), or directly within the form render function. Usage example:

    acfe_form(array(
        'name'         => 'my-form',            // Call by name
        'map'          => array(                // Change field settings
            
            'field_621a65cc5521e' => array(
                'label'        => 'New label',
                'instructions' => 'New instructions',
                'value'        => 'New default value'
            ),
            
        )
    ));
    

    You can also use the native ACF hook acf/prepare_field if you prefer (See documentation).

    The Custom Action hook doesn’t allow to preload value because there is no UI to define which Post/Term/User/Options Page should be used as “Save Target” or “Loading Source”. As you mentioned, those settings are builtin the dedicated WP object Actions such as Post Action, User Action etc…

    It should by used for custom code that isn’t handled by WP, for example when sending data to an external API or service. It can be also used by developers that prefer handle everything within the code, and still being able to repeat the same action in different forms, just by using the same action name.

    Note that Actions in the UI aren’t mandatory, developers can handle everything in code using the Global Form Hooks (Validation, Submission).

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter pankamilr

    (@gordon34)

    @hwk-fr many thanks for you reply and sorry for taking ur free, weekend time. Have a good rest of it!

    • This reply was modified 3 years ago by pankamilr.
    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    It’s okay, no worries ??

    Have a nice day!

    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displaying form values’ is closed to new replies.