Edit post
-
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?
-
yes you can, see FAQs 20 and 23
Thank you!
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.
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
tono
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 filtercf7_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).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]');
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 differentpid
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 thepid
?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
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
oh good! Marking this thread as resolved then
- The topic ‘Edit post’ is closed to new replies.