• Resolved housein

    (@houasein)


    I need a form in a WordPress page that is only accessible to logged-in users. I would like to save user input in the database upon submission. The next time the user loads the page, the fields will be automatically filled with their most recent entries. The field can be edited and resubmitted.

    I have used contact form 7, CF7DB, CF7SG, but I am struggling with using them as default values in cf7 form.

    ‘cf7sg_prefill_form_fields’ filter returns an array of last recorded form values, but how can I pass them default values?

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

    (@aurovrata)

    I have used contact form 7, CF7DB, CF7SG, but I am struggling with using them as default values in cf7 form.

    CF7DB isn’t very flexible as it uses its own custom storage which is external to the WordPress core functionality.

    I have created a plugin to save CF7 submissions called Post My CF7 Form which is fully compatible with CF7SG, and allows you to map a form to a post therefore allowing you to fully leverage WP core functionality to manipulate your data. You may find it more versatile.

    ‘cf7sg_prefill_form_fields’ filter returns an array of last recorded form values, but how can I pass them default values?

    simply overwrite them.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    NOTE: the prefill mechanism on CF7SG was designed for 2 things,

    • prefill default values for a form on loading
    • when you are WP_DEBUG mode, the plugin will save your previously submitted values and prefill them into your form. This is useful for debugging forms, especially long forms where it is time-consuming to fill a form for testing/debugging some other functionality.
    Thread Starter housein

    (@houasein)

    thank you very much for your reply and useful information.
    I did the job with CF7DB and CF7SG’s hooks.
    I’ll definitely check Post My CF7 Form. It seems to be more suitable for what I’m trying to implement. I’ll try it and bother you again with more questions ??
    thank you once again for your help and great job with these plugins.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    I’ll try it and bother you again with more questions

    sure, no problem.

    thank you once again for your help and great job with these plugins.

    welcome. Do leave a review or a coffee to encourage me ??

    Thread Starter housein

    (@houasein)

    I have multiple forms on my website and I want them to be prefilled by the logged-in user’s last entries everytime they load the page.
    CF7DB saves contact forms entries to the database. on form loading using the prefill hook, I get the user’s last record from “_db7_forms” table and return it. BUT if the user submit form A and then try to open form B it returns the last entries of form A!
    I can fix it:
    * if I Have a hidden field to send form key. Then I can iterate through rows to find the last entry that is corresponded to the form. Please let me know if there is a tag to get the form key as a hidden field.
    * If I can get the ‘from_post_id’ in function.php, when ‘cf7sg_prefill_form_fields’ is applied.
    But right now there is no clear way to find the right data. Hook has “cf7_key” which is not in DB and records have ‘from_post_id’ which is not in filter arguments.
    please guide me if you have a solution.|
    Thank you very much.

    Thread Starter housein

    (@houasein)

    PS: I handle the data query in functions.php in my child theme.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    I have multiple forms on my website and I want them to be prefilled by the logged-in user’s last entries everytime they load the page.

    As I mentioned earlier, the Post My CF7 Form plugin is designed for this type of scenarios.

    CF7DB saves contact forms entries to the database.

    however, if you are using CF7DB then you should ask your question in that plugin’s support forum.

    if I Have a hidden field to send form key. Then I can iterate through rows to find the last entry that is corresponded to the form. Please let me know if there is a tag to get the form key as a hidden field.

    what a messy way to go about it. With the Post My CF7 Form, the last submission is a post, so you simply need to get the latest submitted post form that user, and the plugin is already designed to handle form prefills.

    But right now there is no clear way to find the right data. Hook has “cf7_key” which is not in DB and records have ‘from_post_id’ which is not in filter arguments.

    the cf7_key is the form post slug, to uniquely identify the form you are trying to pre-fill. You say you have multiple forms on your site, so you will need to identify them.

    please guide me if you have a solution.

    I don’t use CF7DB so I cannot help you with regards to that plugin. Once you have the form data, you simply feed it to your filter function which you are aleady making use of.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Prefill form fileds with latest entries of logged-in user as default values’ is closed to new replies.