• Resolved Zakir Sajib

    (@zakirstage)


    its been quite 2 days still i cannot figure it out why the page is simply wiped out when submitted a form. i used form’s shortcode to elementor page. But i can add post filling out all custom fields but when i try to edit the form’s custom fields then simply the page is wiped out from the site, even i cannot find that page in trash.

    i am not sure what i missed. All permissions given to user who has author role. I use your plugin to user registration and edit them successfullly only problem is when i edit any custom fields of custom post type and then submit button.

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

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    It’s quite hard to know where the problem come from without more details. The issue could be that you update the Post Type, so the post disappear from the Admin screen and is displayed somewhere else. Hard to tell without more infos.

    Can you please provide the following details:

    • Screenshot of your Form UI, including “Post Action” Save tab
    • The shortcode you’re using to display the form
    • The page relative URL where the shortcode is used (ie: /my-form)
    • Ideally, the Form json export (from the “Custom Fields > Tools” admin menu)

    Thanks in advance!

    Regards.

    Thread Starter Zakir Sajib

    (@zakirstage)

    thank you for quick response.

    here is the link to see all screenshots and json code

    https://drive.google.com/drive/folders/1JvncO755TFHDbpOI9GiqwAueAillto7M?usp=sharing

    And the path of the page is:

    https://tbxtestsrv.com/zephyrs/edit-account/

    so when i submitted, data saved into athlete post into cusotm fields but all the sections i created in edit-account page they also saved. see the screenshots.

    If you want i can share my login access.

    Thank you . Really appreciate.

    and let me know if i miss anything to share.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the details!

    The problem is that you use the Post Action “Target: Current Post” setting. Which means the form will update the Current Post (where the form is displayed).

    In your case, it updates the /edit-account page and change the post type from Page to Athlete (because of the “Post Type: Athelete” setting in the Post Action).

    This is why your “Edit Account” page disappear from the WP Pages Screen, since it becomes an Athlete when the form is submitted.

    If you want to dynamically update the Athlete related to the currently logged user, you’ll have to find the Athlete Post ID using get_current_user_id(), pass the Post ID to the form in PHP, and use it as a “Target” and “Loading Source” in the Post Action.

    See our guide on Passing Data to a Form. You’ll also find more examples and information in the Form Integration documentation.

    Note regarding the “Post Type” setting: When you use an “Update Post” action, you don’t need to set the Post Type setting, unless you really want to change the Post Type. Leaving it to “Default” will leave the Post Type of the “Target” as is (Athlete in your case).

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter Zakir Sajib

    (@zakirstage)

    Yes right. perfect.

    so basically i need to pass is Post ID to target field of save tab of post action box and in load tab in source field. Correct?

    But how can i pass post ID into that form or should i write a code?

    do i have to copy this code into fucntions.php ?

    $profile_id = (int) $_GET['profile_id'];
    
     // make sure profile id exists
     if($profile_id){
         
         // render form
         acfe_form(array(
             'name'       => 'athlete-information-edit-by-parents',
             'profile_id' => $profile_id
         ));
    
     }
    
    add_filter('acfe/form/load/form=athlete-information-edit-by-parents', 'athlete_information_edit_by_parents_settings', 10, 2);
    function athlete_information_edit_by_parents_settings($form, $post_id){
    
        // retrieve url parameter
        $profile_id = (int) $_GET['profile_id'];
        
        // Add Current User ID
        $form['profile_id'] = $profile_id;
        
        // Return
        return $form;
        
    }
     
    
    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    so basically i need to pass is Post ID to target field of save tab of post action box and in load tab in source field. Correct?

    Yes. Remember you’re on an “Edit Account” page, which is totally unrelated from the Athlete, so the form can’t guess what post you want to update. You have to tell it.

    do i have to copy this code into fucntions.php ?

    No, this is an example on how to pass custom data to a form. I don’t know how your Athlete Post can be found from the currently logged user in your case, since it depends on your project structure.

    For example, if each Athlete post has a specific user as author, you could retrieve the Athelete Post by doing a query with get_posts() and use the currently logged user id as author search argument. See documentation. It really depends on your code.

    Note: the first code is for developpers who call acfe_form() directly in the PHP template, the second one is for users who use the [acfe_form] shortcode. You just need to choose one method. In your case it’s the second one.

    Hope it helps!

    Regards.

    Thread Starter Zakir Sajib

    (@zakirstage)

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Please read my answer above.

    The guide is an example on how to pass custom data. Unless you use an URL like edit-account/profile_id=55 to display your form (55 being an athlete post id), it won’t work.

    I don’t know how your Athlete Post can be found from the currently logged user in your case, since it depends on your project structure.

    For example, if each Athlete post has a specific user as author, you could retrieve the Athelete Post by doing a query with get_posts() and use the currently logged user id as author search argument. See documentation. It really depends on your code.

    Regards.

    Thread Starter Zakir Sajib

    (@zakirstage)

    my code structure: athlete is a custom post and with few custom fields from ACF.

    only author can add and edit the athlete posts.

    Adding part is working but edit part is not working so far yet.

    Edit url is https://tbxtestsrv.com/zephyrs/edit-account/

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    I understood it doesn’t work, I’m also trying to explain why it doesn’t work and how to fix it.

    Please take some time to carrefully read the answers I posted. It takes time to write these answers, link documentation etc… I’m all for helping, but you also have to do your part and read it.

    only author can add and edit the athlete posts.

    See my answer above:

    If each Athlete post has a specific user as author, you could retrieve the Athelete Post by doing a query with get_posts() and use the currently logged user id get_current_user_id() as author search argument. See documentation.

    You’ll find code examples in the WP documentation and stackoverflow.

    This part can only be done by you, because you’re the developer who know your code and site structure.

    Regards.

    Thread Starter Zakir Sajib

    (@zakirstage)

    Hey I really appreciate your work and help.

    But i had the impression that plugin will do my job.

    Anyways now it’s clear.

    Have a nice day.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    It will do the job, but you have to tell which post you want to update.

    Remember you’re on an “Edit Account” page, which is totally unrelated from the Athlete, so the form can’t guess what post you want to update. You have to tell it.

    You can try the following code, but I can’t guarantee it will work because I don’t know your site code:

    add_filter('acfe/form/load/form=athlete-information-edit-by-parents', 'athlete_information_edit_by_parents_settings', 10, 2);
    function athlete_information_edit_by_parents_settings($form, $post_id){
    
        // get athlete post from currently logged user
        $athelete_id = get_posts(array(
            'post_type'      => 'zephyrs_athlete',
            'posts_per_page' => 1,
            'fields'         => 'ids',
            'author'         => get_current_user_id()
        ));
        
        // get only the first athlete result
        $athlete_id = $athelete_id[0];
        
        // pass data to the form
        $form['athlete_id'] = $athlete_id;
        
        // return
        return $form;
        
    }
    

    Then you should be able to use {form:athlete_id} as Target.

    If it doesn’t work, then I would recommend to log the get_posts() results with acf_log() see why it can’t retrieve the post. See our guide on Debugging WP & ACF.

    Have a nice day!

    Regards.

    Thread Starter Zakir Sajib

    (@zakirstage)

    Man it works perfectly.

    Super thank you.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    I’m glad to hear it now works as expected!

    Have a nice day!

    Regards.

    Thread Starter Zakir Sajib

    (@zakirstage)

    Hey, i have another question. If you could provide your thoughts.

    I am going to allow users who have author role to add more than one fields using repeater. I can add repeater in form and author can add as many as they want but i am not sure how to let them to edit those fields in post edit mode.

    Can i use repeater in edit mode or something else?

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Please see my answer to your other thread.

    Regards.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Page simpley wiped out after i edit post of custom post type’ is closed to new replies.