prefill doesn’t work with checkboxes
-
I’m using the Smart Grid’s prefill hook to fill CF7 forms with users’ last entries saved in the CF7DB. While it works fine for most fields, it doesn’t properly fill fields like checkboxes with multiple values. The retrieved data and the data returned to the prefill action are correct and sent as an array, but the forms are not being populated with these values.
-
I’m using the Smart Grid’s prefill hook to fill CF7 forms with users’ last entries saved in the CF7DB.
ok, did you try my other plugin, the Post My CF7 Form ? It is specifically designed for saving draft submissions and allowing users to continue where they left off.
While it works fine for most fields, it doesn’t properly fill fields like checkboxes with multiple values.
ok, will need to check this on my test server next week. Will get back to you on this.
Thank you for your prompt response.
did you try my other plugin, the Post My CF7 Form ?
I have it installed already and considering it. But I’ve chosen CF7DB because I found it easier to export recorded data to CSV file.
will need to check this on my test server next week. Will get back to you on this.
Thank you very much. I look forward to your comments on this matter. Meanwhile, I’ll try to run a test with Post My CF7 and see if we can substitute it with CF7DB. with CF7DB.
But I’ve chosen CF7DB because I found it easier to export recorded data to CSV file.
no worries, but keep in mind that the Post My CF7 Form maps your form submission data to the default WP data structures (post, categories, tags, cpt, taxonomies, post meta-data) which can then leverage a wide array of plugins which are designed to work with core WP structures. You will find many plugins that allows export to csv from std wp data structures. With CF7DB, the data is stored in custom tables, and as such 99% of plugins will not be able to access your data. If you intend your website to capture and store data over a long period, then you are better off sticking to core WP framework.
I use Simple CSV Exporter for extracting wp core data to csv files. Although it hasn’t been updated, it still works perfectly last time I used it, a testament to sticking to the core framework, it rarely requires updates.
ok, will need to check this on my test server next week. Will get back to you on this.
Thank you very much. I would appreciate it if you could update me on the test results.
With CF7DB, the data is stored in custom tables, and as such 99% of plugins will not be able to access your data
That’s true. We are strict about the security of our users’ data, so I thought maybe an isolated table could help reduce the risk of data exposure.
It is specifically designed for saving draft submissions and allowing users to continue where they left off.
is there a built-in way to save all form’s fields values (normal and hidden) as post content (in order to export them to CSV file later)?
under Map form fields to default post fields you can only select one field as post content.
I used a cf7_2_post_filter-post-editor to pass the array but it makes it harder later to convert them in a clean table as CSV.It is specifically designed for saving draft submissions and allowing users to continue where they left off.
Is there any clear guidance on how this can be implemented? We want to prefill form fields with the last entries submitted by the logged-in user for each form.
@aurovrata I’d appreciate your help with the “prefill checkboxes” problem and guidance on implementing the “prefill the form with last user entries” using the “Post My CF7” plugin. I’m under time pressure, so your prompt feedback will be greatly valued.
P.S. If I have only one checkbox field in my form and label it exactly “checkbox,” it works. Otherwise, the $field in $.fn.prefillCF7Field in cf7-grid-layout-public.js will be null.
I just checked on my server and the prefill form works as expected, even with multichoice checkbox. Did you check your server/browser for PHP/js errors? Open the browser js console and print your
window
variable. In it you will see a variable calledcf7sg
which will have your form css id value as an attribute,and within which an attribute calledprefill
which list all your form fields for which data has been pre-loaded. Make sure your checkbox values are properly listed there.P.S. If I have only one checkbox field in my form and label it exactly “checkbox,” it works. Otherwise, the $field in $.fn.prefillCF7Field in cf7-grid-layout-public.js will be null.
it looks to me that your field=>value pairs are no longer being listed properly.
Is there any clear guidance on how this can be implemented? We want to prefill form fields with the last entries submitted by the logged-in user for each form.
yes there is a dedicated youtube tutorial on saving draft forms, see the plugin’s tutorials.
We are strict about the security of our users’ data, so I thought maybe an isolated table could help reduce the risk of data exposure.
That’s a false premise in my opinion. A malicious user/plugin will still be able to target your table regardless. In addition, WP security updates that specicifically target DB table access will not cover CF7DB unless that author maitains the plugin properly. Much safer to keep your data into the WP core and trust the large number of WP contributors secure the platform as a whole. It is also important that you harden your server and WP installation
@aurovrata Thank you very much for your response.
As I mentioned before, I’ve checked var cf7sg and the data is there. It’s been correctly loaded and stored in that variable. But it doesn’t change the checkbox’s element status to checked. in other words, it knows which ones should be checked even if form has multiple checkbox fields but it doesn’t visually present them.
It works for the first field if the name is “checkbox” however we still have problems with forms containing more than one checkbox field.
here is an example:
I added some logs in cf7-grid-layout-public.js:
I checked some values:and then submitted the form and reload:
But as you see the rest of the checkboxes are not updated. At this moment this is the cf7sg in the inspector:
var cf7sg = … {“prefill”:{“cfdb7_status”:”unread”,”checkbox”:[“Kirsten Dunst”,”Gwyneth Paltrow”,”Abraham Lincoln, ehem. US-Pr\u00e4sident”,”Buzz Aldrin, zweiter Mann auf dem Mond”],”checkbox-2″:[“Jim Carrey”,”Zach Braff”],”checkbox-3″:[“Katy Perry”],”checkbox-4″:[“Sebastian Deisler, ehem. Fu\u00dfballspieler”],”checkbox-5″:[“J.K. Rowling (Harry Potter)”]}…}
and this is the console:I don’t understand why and how the $field at the first call has all the checkboxes and none later.
I’ve checked var cf7sg and the data is there.
so the plugin is working fine in the backend, its the js that is having problems.
US-Pr\u00e4sident
looks like this could be the problem. Your field values may not match the stored values. THere may be some UTF8 text format issue.
Did you try to debug the
cf7-grid-layout-public.js
script to see if it is able to find your checkbox values?It may very well be a DB configuration issue, and your database is unable to store the UTF8 characters you are using on your front-end, causing the stored values to get messed up.
Compare the checkbox HTML options values with those of your prefill data and see if there are differences there.
Did you try to debug the
cf7-grid-layout-public.js
script to see if it is able to find your checkbox values?
It can’t even get the field object except for the first one in the form. Since the remaining fields are null, it can’t confirm their type as input and returns false.
the values are fine both in prefill data and HTML.I don’t think the problem lies with the stored data. The data is fetched correctly, and the variable
cf7sg
is properly filled. The HTML elements are correctly in place. Everything else works fine for other input types, including the first checkbox field. However, for the remaining checkbox fields, ‘$(this)’ is somehow empty.Ok, I doubled checked and found an error in the js code using the old CF7 HTML markup structure which changed in v5.7 (I think). I fixed this and just release 4.15.8
Can you upgrade and get back to me ?
I updated, and it works fine now.
Thank you very much @aurovrata- This reply was modified 5 months, 2 weeks ago by housein.
Wonderful! Thank you for your patience and perseverance ??
- You must be logged in to reply to this topic.