For all those interested, I hacked together my own solution for this. Seems to work well if you're embedding forms via a function call (which I am in the case of my general contact form):
include('/simple_html_dom.php');
ob_start();
gravity_form(1, false, false, false, '', true);
$gravity_form_output = ob_get_contents();
ob_end_clean();
$gravity_form_clean = str_get_html($gravity_form_output);
$gravity_form_js = '';
foreach($gravity_form_clean->find('script') as $script_tag) {
$gravity_form_js .= $script_tag;
$script_tag->outertext = '';
}
echo $gravity_form_clean;
Then, in the footer (after all of your other javascript), you echo the stripped javascript back:
echo $gravity_form_js;
All this requires is the PHP Simple HTML DOM Parser, which gives us an easy way to strip out HTML nodes. It can be found here: http://simplehtmldom.sourceforge.net/
I'm sure this is kinda hacky and definitely isn't supported, but it seems to work (Gravity guys, I'd love to hear if this might cause any issues that you can think of), prevents me from having to touch the plugin so that it can be upgraded properly, and allows me to move jQuery back to the footer.
Posted 12 years ago on Sunday September 9, 2012 |
Permalink