function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Margaret FleischakerMargaret Fleischaker 

reCaptcha in Lightning Community web-to-case form - error adding <script>

I'm trying to use the HTML generated from the web-to-case form to add reCaptcha to a web-to-case form in a Lightning Community component. I'm running into the error that the script tag is not allowed. I'm assuming this is because it is in Lightning. Is there a simple workaround? I've seen some comments online about building a Visualforce page with the  and including it in the HTML component as an iframe; is that the best approach?
 
<script src="https://www.google.com/recaptcha/api.js"></script>
<script>
 function timestamp() { var response = document.getElementById("g-recaptcha-response"); if (response == null || response.value.trim() == "") {var elems = JSON.parse(document.getElementsByName("captcha_settings")[0].value);elems["ts"] = JSON.stringify(new Date().getTime());document.getElementsByName("captcha_settings")[0].value = JSON.stringify(elems); } } setInterval(timestamp, 500); 
</script>

 
Best Answer chosen by Margaret Fleischaker
Margaret FleischakerMargaret Fleischaker
In order to avoid having to manually update the static resource when new recaptcha version are released, I ended up creating a lightning component with a visualforce page embedded in it. I found this to be helpful: http://sfdcode.com/lightning/lightning-recaptcha-lightning-components/

All Answers

Philip FPhilip F
I have included a static version of the recatpcha library in a static resource and it works fine.  But you'll need to update the static resource manually as new recaptcha versions are released.

I  haven't tried this in lightning, so YMMV, but I believe you could put the api.js file contents and your script method into one or more static resources, include them in your lightning component, then access the methods in lightning.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_libs_platform.htm 
Margaret FleischakerMargaret Fleischaker
In order to avoid having to manually update the static resource when new recaptcha version are released, I ended up creating a lightning component with a visualforce page embedded in it. I found this to be helpful: http://sfdcode.com/lightning/lightning-recaptcha-lightning-components/
This was selected as the best answer