• Resolved athep

    (@athep)


    Hello!

    I was wondering if it was possible to pre-fill a form page with a previously submitted entry for easier non-backend editing, how can I achieve this?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    yes you can, see FAQs 20 and 23

    Thread Starter athep

    (@athep)

    Thank you!

    Thread Starter athep

    (@athep)

    Hello, I read the F.A.Q and also watched your video on this topic, I’d like to ask how I would go about creating a link that would pre-fill the add post page with the post I want edited, this means the link passing the post ID?

    I’m not very proficient with backend so I did my best to implement the code you added on your F.A.Q

    Also thank you for the life saving plugin! Great work.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    how I would go about creating a link that would pre-fill the add post page with the post I want edited, this means the link passing the post ID?

    Sure, but i would pass it as a query parameter to your link, something like yourdomain.com/form-edit/?pid=123

    On your form-edit page you want to look for your $_GET query parameter and then ensure the post is editable by the current user (as a security option to stop someone hacking the link).

    Now you can do either of 2 things,

    1. if the current user is the author of the post, then simple set the post’s meta field _cf7_2_post_form_submitted to no and the plugin will pick up that post for editing, pre-filling the values in the mapped form.

    2. You can by-pass the post query by forcing the post to be loaded for this query, for example the post__in property using the filter cf7_2_post_filter_user_draft_form_query (you have a helper code available in the form’s editor page Actions & Filters metabox (see the screenshot #8).

    Plugin Author Aurovrata Venet

    (@aurovrata)

    PS: another way is to programmatically load the form shortcode and add the cf7_2_post_id attribute, but you will still need to do step 1 above.

    do_shortcode('[contact-form-7 id=... cf7_2_post_id=123]');

    Thread Starter athep

    (@athep)

    I’m not good with PHP, I did however got a bit lucky with this snippet, this is after checking the author credentials and all.

    $pid = $_GET['pid'];
    if( isset( $pid ) && get_post_status( $pid ) ) {
    	update_post_meta($pid, '_cf7_2_post_form_submitted' ,'no');
    } else {
    	update_post_meta($pid, '_cf7_2_post_form_submitted' ,'yes');
    }

    The problem I have with this code is that the else part is not working.. if someone sets a different pid on /?pid=123 then the last post I set up for editing still shows up unless I click on submit.

    What can I do to set the form to only receive the form details of pid and not stay there once I change the pid?

    Plugin Author Aurovrata Venet

    (@aurovrata)

    The problem I have with this code is that the else part is not working.. if someone sets a different pid on /?pid=123 then the last post I set up for editing still shows up unless I click on submit.

    well is the $pid isn’t set then surely you want to load a black form, no? In which case simply force the form pre-filling query to return a null result.

    What can I do to set the form to only receive the form details of pid and not stay there once I change the pid?

    I am not sure I follow what you mean

    Thread Starter athep

    (@athep)

    well is the $pid isn’t set then surely you want to load a black form, no? In which case simply force the form pre-filling query to return a null result.

    Thank you, this worked well

    Plugin Author Aurovrata Venet

    (@aurovrata)

    oh good! Marking this thread as resolved then

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Edit post’ is closed to new replies.