You cannot inject a shortcode on the front end and expect it to render a form. Shortcodes cN only be executed and their content rendered on the server. If you want to display a form when a button is clicked, render the form as usual and hide it until the button is clicked or create an Ajax function to render and display the form.
That's what I've done, I've got an API route that does a do_shortcode and render the form correctly, no problem there.
I just need to load the scripts needed for recaptcha and ajax submission to work properly. And I don't seem to have a trigger to do that.
But thanks for your answer.
I don't think you understood my suggestion. I suggested to stop using Ajax to render the form with do shortcode. When you add your form to a page, wrap the shortcode in a div element and set the div element to display: none. When a user clicks a button, use jQuery to show() the div element and display the form. Everything will work as expected.
I understand, but it's not a solution that suits me. The original purpose of this deferred rendering is to avoid loading the Formidable Forms scripts when the page loads, in order to improve site performance.
But thanks for your suggestion.
Formidable's scripts won't overload a page. What will slow down a page is very long forms with hundreds of fields and Ajax. If Formidable's scripts are slowing down your page, I suspect you got other things going on that impacts performance on your server.
On a page with several forms configured with Recaptcha, the linked scripts are loaded as many times. This is a problem reported by pagespeed.web that I'd like to fix.
Please login or Register to submit your answer