• Resolved ahmadabdillah

    (@ahmadabdillah)


    Hi,

    I have used a plugin to create a form for user to update from frontend some ACF fields that I used.
    However, the form showed the input by user but it is not reflected on the admin backend of the site.

    Example, I have 3 checkbox option.
    1) personal trainer
    2) health trainer
    3) sports coach

    User update by clicking option 1 & 2.
    From the backend, the trainers are custom post types but it is not updated according to user changes.
    However, from the form in the frontend, the option stayed as what user had updated.

    Hope you can help me out here.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback! Can you please share screenshots from your ACF Extended Form configuration, “Post Action” tabs & the code you’re using to display the form? I’ll need those information in order to help you.

    Thanks in advance.

    Regards.

    Thread Starter ahmadabdillah

    (@ahmadabdillah)

    Let me explain in detail

    I have used acf pro to modify this plugin. There is 2 type of user and these 2 users are link to custom post.

    I had use forms to display my acf fields for these custom posts so that user can edit and save in the frontend. The form display all the fields nicely but the problem is, it didn’t update the fields on the post on backend.
    This is the screen shoot: http://prnt.sc/tmr49b

    Right below are the acf fields which was not updated at all

    However, on the form after user click the update button, the changes that the user made is still there.

    I think it might be the target source where the fields are updated.
    http://prnt.sc/tmr0z1
    This is showing the action for my form. I had use update post and update user for the action of the form.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback. Let’s focus on one form, the “Update Form”. The “Save Target” you defined is Current Post ID, which means the data will be updated on the post/page where the Form is being disapled (using acfe_form() or [acfe_form]).

    In order to correctly save the meta, you’ll have to check the field in the “Save ACF Fields” setting. If you want to load the data that is already saved in DB, you can enable the “Load Values” setting in the “Load” tab. Again, remember to check which fields you would like to have their values loaded.

    See screenshots: https://imgur.com/a/UHWC9mM
    Video example: https://i.imgur.com/Vc3M53B.mp4

    If your form isn’t displayed on the targeted post/page, then you’ll have to use the acfe/form/submit/post_args hook, which let you change the post/page update arguments, just like you would do with wp_update_post().

    Usage example:

    add_filter('acfe/form/submit/post_args/form=my-form', 'my_form_post_args', 10, 4);
    function my_form_post_args($args, $type, $form, $action){
    
        /**
         * @array   $args   The generated post arguments
         * @string  $type   Action type: 'insert_post' or 'update_post'
         * @array   $form   The form settings
         * @string  $action The action alias name
         */
    
        // Retrieve the correct targeted post ID
        $target_post_type = 123;
        
        // Change the Post ID that will be updated
        $args['ID'] = $target_post_type;
        
        /**
         * Return arguments
         * Note: Return false will stop post & meta insert/update
         */
        return $args;
        
    }
    

    You’ll find more code examples in the “Code” tab in the “Post” Action.

    Hope it helps!

    Regards.

    Thread Starter ahmadabdillah

    (@ahmadabdillah)

    Hi

    I am not really an expert in coding, just minimal experience and hope you can help me out here.

    I have checked and tried this code and added it in function.php in my child theme.

    add_filter('acfe/form/submit/post_args/form=trainer-detail', 'trainer_details_form', 10, 4);
    function trainer_details_form($args, $type, $form, $action){
    
        /**
         * @array   $args   The generated post arguments
         * @string  $type   Action type: 'insert_post' or 'update_post'
         * @array   $form   The form settings
         * @string  $action The action alias name
         */
    
        // Retrieve the correct targeted post ID
        $target_post_type = get_field('my_field');
        
        // Change the Post ID that will be updated
        $args['$candidate_id'] = $target_post_type;
        
        /**
         * Return arguments
         * Note: Return false will stop post & meta insert/update
         */
        return $args;
        
    }

    And call up the function in my page by adding this code:

    <?php acfe_form('trainer-detail'); 
    $trainer_details = get_field('group_5f1877f981d82',  $candidate_id);
    echo apply_filters('trainer_details_form', $trainer_details, $candidate_id);
    ?>

    However, the value is still not saved in the database. What did I went wrong?

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    There are multiple parts of your code that don’t make sense:

    $target_post_type = get_field('my_field');
    $args['$candidate_id'] = $target_post_type;
    

    get_field('group_5f1877f981d82', $candidate_id);

    In the hook in my previous answer, you have to change the $args['ID'] key, not create a new one $args['$candidate_id'].

    What you’re trying to achieve is very vague, you don’t give me enough information to help you and it looks like you’re trying to plug it with an another plugin. I’ll be able to help you if you give me information on where the form is being displayed, what it is suppose to update. You should provide as much screenshots and videos as possible to help me understand.

    If you’re not much confortable with PHP development, maybe you should hire a developer to help you or find a more “non-dev” friendly form solution. ACF & ACF Extended are solutions that are designed for developers.

    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘ACF Form Value not updated backend’ is closed to new replies.