Hello @renplainview
Thank you very much for using our plugin.
Your “select” field has the structure:
[selct_multiselct* number placeholder:--- "1" "2" "3" "4" "5"]
And you want to select the option whose value matches with the current post excerpt (the post where the form is inserted).
To read the current post_excerpt you should use the recordset structure:
[cf7-recordset id="cf7-recordset-414" type="post" attributes="post_excerpt" condition="ID={post.id}"]
The condition ID={post.id} tell the plugin you want to filter the data by the current post’s id.
Finally, to select the corresponding option in the multi-select field, you should subscribe to the recordset event.
Note that you don’t want to replace the values in the multi-select field but only to select its choices.
<script>
document.addEventListener('cf7-recordset', function(evt){
if(evt.detail['recordset-id'] == 'cf7-recordset-414')
{
jQuery('[name="number"] option[value="'+evt.detail['recordset-data'][0]['post_excerpt']+'"]').prop('selected', true).change();
}
}); </script>
The complete structure would be:
[selct_multiselct* number placeholder:--- "1" "2" "3" "4" "5"]
[cf7-recordset id="cf7-recordset-414" type="post" attributes="post_excerpt" condition="ID={post.id}"]
<script>
document.addEventListener('cf7-recordset', function(evt){
if(evt.detail['recordset-id'] == 'cf7-recordset-414')
{
jQuery('[name="number"] option[value="'+evt.detail['recordset-data'][0]['post_excerpt']+'"]').prop('selected', true).change();
}
}); </script>
Best regards.
Thank you for the detailed response. It turned out that everything only works fine if you are logged into the WordPress admin. If you check from incognito, there is an error in the console:
VM1774:2 Uncaught ReferenceError: cf7_datasource_register_recordset is not defined
at <anonymous>:2:1
at (index):3:5388
at new Promise (<anonymous>)
at RocketLazyLoadScripts._transformScript ((index):3:5080)
at async RocketLazyLoadScripts._loadScriptsFromList ((index):3:5481)
You can see it yourself at https://studibucht.de/test-page/. CF7 is at the bottom of the page, the “Arbeitstyp” field should display “Masterarbeit” by default when the page loads. This is what happens when you are logged in.
We are using WPRocket and I thought at first it was all about jQuery, I specifically turned off all restrictions for jQuery. But it still doesn’t work.
Could you suggest a solution to this problem?
Hello @renplainview
Could you please modify the settings of WP Rocket? Specifically the way it loads the javascript resources, and purge its cache.
Please, visit your website with the nocache parameter for testing:
https://studibucht.de/test-page/?nocache=1
Best regards.
I have the same problem using wp-rocket.
We have to exclude some of the scripts form the js delay of wp rocket.
But after long testing, i cant find out the right settigs.
i think the problem is the inline script containing f7_datasource_register_recordset. I think this should not be a inline script that it will working with wp rocket.
Best regards.
Hello @jannnfe
You can exclude the inline scripts from WP Rocket settings:

Best regards.
Hello,
Unfortunately that doesn’t help me to solve the problem. Do you have any other idea what to add to the exclusion list?
Best regards.
Hello @jannnfe
Could you please indicate the URL to the page to check if your website is loading the plugin resources in the correct order?
Best regards.
Hello @jannnfe
Please, look at the source code of your page:
<script data-minify="1" type='text/javascript' src='https://umbracanis.de/wp-content/cache/min/1/wp-content/plugins/cf7-data-source/assets/script.js?ver=1657120463' id='cf7_datasource_script-js' defer></script>
<script type='text/javascript' id='cf7_datasource_script-js-after'>
cf7_datasource_register_recordset("hundenamen-list", {"fields":[],"variables":[],"cf7":2399}, 194)
cf7_datasource_register_link({"recordset":"hundenamen-list","field":"tv_name","value":"post_title","text":"post_title","condition":"","limit":"","default":[],"fields":[],"variables":[]}, 194)
</script>
The code in the inline script should work after loading the script.js file, but “WP Rocket” ignores the Scripts dependency.
To fix this issue, please, configure the “Defer” options in the “WP Rocket” to not apply the defer to the “cf7-data-source/assets/script.js” script.
Best regards.
Thanks! I added the following in WPRocket defer exclude and now its working:
/jquery-?[0-9.](.*)(.min|.slim|.slim.min)?.js
/cf7-data-source/assets/script(.min)?.js
Best regards.
-
This reply was modified 3 years, 11 months ago by
jnnfx.
-
This reply was modified 3 years, 11 months ago by
jnnfx.
Hello @jannnfe
Excellent !!! Thank you very much for sharing your solution.
Best regards.