• Resolved tryanc

    (@tryanc)


    Hi Aurovrata,

    First off, thank you for your hard work on an amazing plugin. I am trying to track down a strange issue that started occurring after I added this plugin to an existing CF7 form. I have the form setup to create a custom post type, and it uses two default fields as well as two custom meta fields to create the post. Creating the post when the form is submitted has generally been working without any issues.

    However, when logged in as a specific admin, certain inputs are getting pre-filled with matching values from previously published custom posts. Generally its 1-2 of the 4 inputs. And if I submit the form, the existing post is overwritten with the new values, rather than creating a new post. It seems to generally try to populate the fields from the most recently published post. Another strange issue is that this only happens when submitting forms as a specific admin user. Logging in and trying the same thing as a different admin user (or logged out) doesn’t cause any of these issues.

    I’m really stumped here. I am not using any of your custom hooks or filter. I would greatly appreciate any help or guidance!

    Btw, the issue is appearing with modal “Share Your Story” form on the page listed above.

    Thanks,
    Tim

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

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

    (@aurovrata)

    Hi Tim,

    glad u like the plugin, do leave a review on the plugin page when you have some time.

    What you are observing is part of the design of the plugin,

    […] when logged in as a specific admin, certain inputs are getting pre-filled with matching values from previously published custom posts. Generally its 1-2 of the 4 inputs.

    basically the idea is that for a given user/author, a submission can be saved as a draft and modified till the final version is submitted. By default the final submission is not published but remains as draft.

    As of v1.3 of this plugin, I track submitted forms using a meta-field _cf7_2_post_form_submitted with values yes|no, this permits the tracking of draft (saved) forms as opposed to submitted ones. Prior to v1.3 this was done using the status of the post which was not very reliable.

    So what you are experiencing is normal, the admin user has either old post created prior to v1.3 which are in draft mode, or recent post which have not been submitted as yet.

    with v3.3 you can toggle this status in the saved post quick-edit, allowing you to set these submissions to submitted, which will stop the plugin loading them in the front-end for that given author.

    And if I submit the form, the existing post is overwritten with the new values, rather than creating a new post.

    indeed, because the form is now pre-loaded with an existing post to which the subsequent saving needs to be done to, thus tracking the post ID.

    It seems to generally try to populate the fields from the most recently published post.

    yes, since if there are multiple post for an author that are in a non-submitted state, the plugin just takes the first one it finds (which the query orders chronologically by default).

    Finally, there is a way to switch off the mechanism to load un-submitted forms altogether, using the filter cf7_2_post_filter_user_draft_form_query which expects an array of arguments for the post query. simply return an empty array so no posts will be found,

    add_filter('cf7_2_post_filter_user_draft_form_query', 'no_draft_forms',10,2);
    function no_draft_forms($args, $post_type){
      if('my-stories' != $post_type) return $args;
      return array();
    }

    you could also tweak the arguments for a specific author only.

    Thread Starter tryanc

    (@tryanc)

    Thank you for the quick and detailed response!! I ended up using the filter to achieve what we wanted. I will be sure to add a review. Best wishes!

    Thread Starter tryanc

    (@tryanc)

    Actually it appears that my issue isn’t fully resolved, and I think I’ve caused some additional issues by deleting the previous CF7 form (in order to re-map the fields with your plugin) and re-creating it with a new mapping.

    no_draft_forms wasn’t initially working but I tried your suggestion above with load_published_submissions based on your documentation. Should this have the same effect?

    add_filter('cf7_2_post_filter_user_draft_form_query', 'load_published_submissions',10,2);
    function no_draft_forms($args, $post_type){
      if('story_submissions' != $post_type) return $args;
      return array();
    }

    This caused story_submissions drafts to stop pre-filling the the values. However it appears that I am now seeing one field filled with the title from a generic post. Any ideas as to what might have happened?

    Also, I initially did see the ability to mark a post as submitted via the quick edit menu, however after re-creating the CF7 form with new mappings, it appears that option has disappeared.

    Thanks in advance!

    Plugin Author Aurovrata Venet

    (@aurovrata)

    Should this have the same effect?

    no, none whatsoever, as your filter is now calling a non-existent function, it is trying to call a function load_published_submissions but your function is actually called no_draft_forms… in fact you should be having an error thrown by your code.

    However it appears that I am now seeing one field filled with the title from a generic post. Any ideas as to what might have happened?

    difficult to tell without seeing your code.

    however after re-creating the CF7 form with new mappings, it appears that option has disappeared.

    the quick-edit setup if only for posts that are mapped using this plugin. So if you are mapping a new post, the old post would not have the quick-edit setup anymore.

    If you are struggling with filters and custom PHP functionality, you can read up the codex documentation for more details. If you need help with setting up your custom code, you can reach me on vrata at syllogic dot in

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Mystery prefilling of some CF7 inputs’ is closed to new replies.