{"id":2860,"date":"2022-11-21T19:02:53","date_gmt":"2022-11-21T19:02:53","guid":{"rendered":"https:\/\/obo.zoj.mybluehost.me\/uncategorized\/add-recaptcha-v2-to-your-forms\/"},"modified":"2025-01-24T14:40:44","modified_gmt":"2025-01-24T14:40:44","slug":"add-recaptcha-v2-to-your-forms","status":"publish","type":"post","link":"https:\/\/ioninteractive.com\/ionacademy\/add-recaptcha-v2-to-your-forms\/","title":{"rendered":"How to add reCAPTCHA to a form"},"content":{"rendered":"\n<p>CAPTCHA is an acronym for Completely Automated Public Turing test to tell computers and humans apart. Typically, CAPTCHA serves-up a checkbox that must be checked before a form can be submitted to prevent non-humans from submitting.<\/p>\n\n\n\n<p>You can use <strong>Google&#8217;s reCAPTCHA v2 <\/strong>to add this functionality to your Ion experiences.&nbsp;First, you&#8217;ll need to pick up a <strong>secret key<\/strong> and a <strong>site key<\/strong> by visiting this link (https:\/\/www.google.com\/recaptcha\/admin\/create) to log-in to Google reCAPTCHA v2. You can log-in using an existing Google account or by creating a new one.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/obo.zoj.mybluehost.me\/wp-content\/uploads\/2023\/08\/image-3-Sep-30-2022-01-35-48-25-PM.png\" alt=\"image (3)-Sep-30-2022-01-35-48-25-PM\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Attachments<\/h3>\n\n\n\n<p>Server scriptlet and javascript samples are attached to this support post, so you can add them into your console&#8217;s server scriptlet and script libraries, respectively.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/f.hubspotusercontent30.net\/hubfs\/355484\/reCAPTCHA%20Server%20Scriptlet-2.txt\" target=\"_blank\" rel=\"noopener\">reCAPTCHA Server Scriptlet.txt<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/f.hubspotusercontent30.net\/hubfs\/355484\/reCAPTCHA%20Page%20Script-2.txt\" target=\"_blank\" rel=\"noopener\">reCAPTCHA Page Script.txt<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/f.hubspotusercontent30.net\/hubfs\/355484\/reCAPTCHA%20Widget-2.txt\" target=\"_blank\" rel=\"noopener\">reCAPTCHA Widget.txt<\/a><\/li>\n<\/ul>\n\n\n\n<p>You&#8217;ll use these attachments and follow the steps listed below to add reCAPTCHA v2 to your Ion Forms.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Server Scriptlet<\/strong><\/h3>\n\n\n\n<p>Let&#8217;s add the server scriptlet to your console first and make minor adjustments to the attached server scriptlet sample<span style=\"font-size: medium\">:<\/span><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the &#8220;reCAPTCHA Server Scriptlet&#8221; attachment and copy the code (<a href=\"https:\/\/f.hubspotusercontent30.net\/hubfs\/355484\/reCAPTCHA%20Server%20Scriptlet-2.txt\" target=\"_blank\" rel=\"noopener\">reCAPTCHA Server Scriptlet.txt<\/a>).<\/li>\n\n\n\n<li>Click the Libraries menu in your console\u2019s side nav and select &#8220;Server Scriptlets.&#8221;<\/li>\n\n\n\n<li>Add a scriptlet category or navigate into an existing one.<\/li>\n\n\n\n<li>Click green &#8221; New scriptlet&#8221; button to add a new reCAPTCHA server scriptlet to the selected category.<\/li>\n\n\n\n<li>Give your scriptlet a title and paste &#8220;reCAPTCHA Server Scriptlet&#8221; code into the editor.<\/li>\n\n\n\n<li>Replace <strong>secret key <\/strong>example value of &#8220;XXXXXX&#8221; with your secret key. Please note that the double quotes should remain wrapped around your value.<\/li>\n\n\n\n<li>Save<\/li>\n\n\n\n<li>Click scriptlet title to navigate back into the scriptlet and view the URL in your browser window. Make a note of the sscID value in the URL in your address bar. This value will be referenced in the javascript set up in the next section.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"533\" loading=\"lazy\" src=\"https:\/\/obo.zoj.mybluehost.me\/wp-content\/uploads\/2025\/01\/Screenshot_8-5-1024x533.png\" alt=\"\" class=\"wp-image-7332\" srcset=\"https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_8-5-1024x533.png 1024w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_8-5-300x156.png 300w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_8-5-768x400.png 768w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_8-5-1536x799.png 1536w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_8-5.png 1910w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Javascript<\/strong><\/h3>\n\n\n\n<p>Next, let&#8217;s add some javascript to your console that will run the server scriptlet and perform CAPTCHA validation upon form submission<span style=\"font-size: medium\">:<\/span><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the &#8220;reCAPTCHA Page Script&#8221; attachment and copy the code (<a href=\"https:\/\/f.hubspotusercontent30.net\/hubfs\/355484\/reCAPTCHA%20Page%20Script-2.txt\" target=\"_blank\" rel=\"noopener\">reCAPTCHA Page Script.txt<\/a>).<\/li>\n\n\n\n<li>Click Libraries menu in your console\u2019s side nav and select &#8220;Scripts.&#8221;<\/li>\n\n\n\n<li>Add a script category or navigate into an existing one.<\/li>\n\n\n\n<li>Click green &#8220;New script&#8221; button to add a new script to the selected category.<\/li>\n\n\n\n<li>Give your script a title and paste &#8220;reCAPTCHA page script&#8221; code into the editor.<\/li>\n\n\n\n<li>Replace the <strong>scriptletID <\/strong>value of X with sscID value from your server scriptlet as noted in step 8 of Server Scriptlet section above.<\/li>\n\n\n\n<li>Save<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"887\" loading=\"lazy\" src=\"https:\/\/obo.zoj.mybluehost.me\/wp-content\/uploads\/2025\/01\/Screenshot_9-6-1024x887.png\" alt=\"\" class=\"wp-image-7333\" srcset=\"https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_9-6-1024x887.png 1024w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_9-6-300x260.png 300w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_9-6-768x665.png 768w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_9-6.png 1066w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Widget<\/strong><\/h3>\n\n\n\n<p>Now we are going to create a widget that will be dragged into your ion page(s) to add CAPTCHA to your form(s)<span style=\"font-size: medium\">:<\/span><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the &#8220;reCAPTCHA Widget&#8221; attachment and copy the code (<a href=\"https:\/\/f.hubspotusercontent30.net\/hubfs\/355484\/reCAPTCHA%20Widget-2.txt\" target=\"_blank\" rel=\"noopener\">reCAPTCHA Widget.txt<\/a>).<\/li>\n\n\n\n<li>Click the Libraries menu in your console\u2019s side nav and select &#8220;Widgets.&#8221;<\/li>\n\n\n\n<li>Click green \u201cNew widget\u201d button at the top of the page to add a new widget.<\/li>\n\n\n\n<li>Give your widget a name and select a category or create a new one for your widget.<\/li>\n\n\n\n<li>Paste &#8220;reCAPTCHA Widget&#8221; code.<\/li>\n\n\n\n<li>Replace <strong>site key <\/strong>example value of &#8220;XXXXXX&#8221; with your&nbsp;<strong>site key. <\/strong>Please note that the double quotes should remain wrapped around your value.<\/li>\n\n\n\n<li>Save<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"475\" loading=\"lazy\" src=\"https:\/\/obo.zoj.mybluehost.me\/wp-content\/uploads\/2025\/01\/Screenshot_10-6-1024x475.png\" alt=\"\" class=\"wp-image-7334\" srcset=\"https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_10-6-1024x475.png 1024w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_10-6-300x139.png 300w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_10-6-768x356.png 768w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_10-6-1536x712.png 1536w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_10-6.png 1696w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Page Setup<\/strong><\/h3>\n\n\n\n<p>With the scriptlet, page script and widget ready, it&#8217;s time to bring it all together in your page.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Navigate into your form page<\/li>\n\n\n\n<li>Open the script editor and add the reCAPTCHA page script to the &lt;head&gt;<\/li>\n\n\n\n<li>Click OK<\/li>\n\n\n\n<li>Hover over the Basics category in your creative studio and drag widget icon into your form just above the submit button.<\/li>\n\n\n\n<li>Select reCAPTCHA widget<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"925\" height=\"852\" loading=\"lazy\" src=\"https:\/\/obo.zoj.mybluehost.me\/wp-content\/uploads\/2025\/01\/Screenshot_11-5.png\" alt=\"\" class=\"wp-image-7335\" srcset=\"https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_11-5.png 925w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_11-5-300x276.png 300w, https:\/\/ioninteractive.com\/ionacademy\/wp-content\/uploads\/2025\/01\/Screenshot_11-5-768x707.png 768w\" sizes=\"auto, (max-width: 925px) 100vw, 925px\" \/><\/figure>\n\n\n\n<p>Your form should now be all set to use CAPTCHA to verify that a human is submitting the form and not a robot!<\/p>\n\n\n\n<p><strong>*Notes: <\/strong>After following this tutorial, you can preview your Ion experience and run a test. If you see the error message below, you will need to check and fix the<strong> domain <\/strong>you added in&nbsp;Google settings:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/obo.zoj.mybluehost.me\/wp-content\/uploads\/2023\/08\/image-Sep-30-2022-02-11-46-02-PM.png\" alt=\"image-Sep-30-2022-02-11-46-02-PM\" \/><\/figure>\n\n\n\n<p>And if you see the error message below, you will need to check and fix the<strong> site key <\/strong>value you used in the steps of this post:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/obo.zoj.mybluehost.me\/wp-content\/uploads\/2023\/08\/image-1-Sep-30-2022-02-13-46-14-PM.png\" alt=\"image (1)-Sep-30-2022-02-13-46-14-PM\" \/><\/figure>\n\n\n\n<p>If the following message show up instead, it means the key type you are using it&#8217;s not compatible with the recaptcha version you are installing. This tutorial refers to <strong>v2 type<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/obo.zoj.mybluehost.me\/wp-content\/uploads\/2023\/08\/image-png-Nov-21-2022-07-01-17-5182-PM.png\" alt=\"\" \/><\/figure>\n\n\n\n<p><em><strong>*Notes: <\/strong>this set up was built for standard form pages. If you try to configure a different type of page &#8211; that is not a form &#8211; it may not work correctly.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Library Forms: Adding CAPTCHA to custom HTML forms<\/h2>\n\n\n\n<p>You can use Google&#8217;s gratis reCAPTCA product to add CAPTCHA functionality to your ion experiences. To include a CAPTCHA tool on your form(s), you&#8217;ll leverage ion&#8217;s custom HTML form feature. Please note, CAPTCHA is not available for table-generated forms. Now, let&#8217;s get started!<br data-aura-rendered-by=\"75:426;a\"><br data-aura-rendered-by=\"75:426;a\">First, you&#8217;ll need to pick up a secret&nbsp;key and a site&nbsp;key by visiting the link below to log-in to Google reCAPTCHA. You can log-in using an existing Google account or by creating a new one:<br data-aura-rendered-by=\"75:426;a\"><a href=\"https:\/\/www.google.com\/recaptcha\/admin\/create\" target=\"_blank\" rel=\"noopener\" data-aura-rendered-by=\"75:426;a\">https:\/\/www.google.com\/recaptcha\/admin\/create<\/a><br data-aura-rendered-by=\"75:426;a\"><br data-aura-rendered-by=\"75:426;a\">A server scriptlet and custom HTML form sample are attached to this support post that you can plug into your console. You&#8217;ll use these attachments and follow the steps listed below to add a form with CAPTCHA to your ion pages. Now, let&#8217;s add the scriptlet to your console, making minor updates to the sample:<br data-aura-rendered-by=\"75:426;a\"><br data-aura-rendered-by=\"75:426;a\">1. Open the scriptlet attachment and copy the code.<br data-aura-rendered-by=\"75:426;a\">2. Navigate to the global Libraries&nbsp;menu and select &#8220;server scriptlets.&#8221;<br data-aura-rendered-by=\"75:426;a\">3. Add a scriptlet category or navigate into an existing one. Paste your code into the editor.<br data-aura-rendered-by=\"75:426;a\">4. Find the line of code that includes &#8220;URL += &#8220;secretkey=xxxSecretKey&#8221;;&#8221; and replace &#8220;xxxSecretKey&#8221; with the one you obtained from Google, then save.<br data-aura-rendered-by=\"75:426;a\">5. Navigate back into the scriptlet and view the URL in your browser window. Make a note of the sscID value in the URL.<br data-aura-rendered-by=\"75:426;a\"><br data-aura-rendered-by=\"75:426;a\">Next, let&#8217;s add the custom form to your ion console. Attached to this support post, you&#8217;ll find a sample custom HTML form that includes the reCATCHA JavaScript outside of the form tags.&nbsp;<br data-aura-rendered-by=\"75:426;a\"><br data-aura-rendered-by=\"75:426;a\">1. Open the custom form attachment and copy the code.<br data-aura-rendered-by=\"75:426;a\">2. In your console, navigate to the global Libraries menu and select &#8220;forms.&#8221;<br data-aura-rendered-by=\"75:426;a\">3. Add a form category, or navigate into an existing one, then add a new form. Label the form, select custom HTML as the &#8220;form type&#8221; and save.<br data-aura-rendered-by=\"75:426;a\">4. Paste your sample form code into the editor.<br data-aura-rendered-by=\"75:426;a\">5. Find the line containing &#8220;Recaptcha.create(&#8220;xxxCAPTCHAkey&#8221;, element, {&#8221; and replace &#8220;xxxCAPTCHAkey&#8221; with the site&nbsp;key you&#8217;ve generated in Google.&nbsp;<br data-aura-rendered-by=\"75:426;a\">6. Find the line containing &#8220;result = liveballScriptlet(1,&#8221;rct=json&#8221;,reqStr);&#8221; and replace 1 with the &#8220;sscID&#8221; value you&#8217;ve noted earlier.<br data-aura-rendered-by=\"75:426;a\">7. Save.<br data-aura-rendered-by=\"75:426;a\"><br data-aura-rendered-by=\"75:426;a\">This example uses the &#8220;white&#8221; theme for the CAPTCHA. See Google&#8217;s reCaptcha support if you wish to change the theme.<br data-aura-rendered-by=\"75:426;a\"><br data-aura-rendered-by=\"75:426;a\">A developer can code additional data fields into this sample form or simply use it as a reference point. If you want to save the data field values into your console, click on the pencil icon labeled &#8220;save as is&#8221; beside each field, and from the drop-down menus you&#8217;ll select the corresponding ion data collection field.&nbsp;<br data-aura-rendered-by=\"75:426;a\"><br data-aura-rendered-by=\"75:426;a\">Last but not least, let&#8217;s add the form to a test creative:<br data-aura-rendered-by=\"75:426;a\"><br data-aura-rendered-by=\"75:426;a\">1. Navigate to a testing or sandbox Portfolio &gt; Campaign and add a creative with a form editor.<br data-aura-rendered-by=\"75:426;a\">2. Click over the form editor and select the form with CAPTCHA you&#8217;ve just added to your console.<br data-aura-rendered-by=\"75:426;a\">3. Link the form to a follow-on page<br data-aura-rendered-by=\"75:426;a\"><br data-aura-rendered-by=\"75:426;a\">Now you&#8217;re ready to test your form with CAPTCHA!&nbsp;<br data-aura-rendered-by=\"75:426;a\"><br data-aura-rendered-by=\"75:426;a\">The ion team is available to implement this for you as a project, if you&#8217;d prefer for us to do the legwork. Feel free to contact your Account Manager if you have any questions.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/f.hubspotusercontent30.net\/hubfs\/355484\/CAPTCHA.zip\" target=\"_blank\" rel=\"noopener\">CAPTCHA.zip<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>CAPTCHA is an acronym for Completely Automated Public Turing test to tell computers and humans apart. Typically, CAPTCHA serves-up a checkbox that must be checked before a form can be submitted to prevent non-humans [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":5692,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[2082,2078],"tags":[2173,2144],"class_list":["post-2860","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scriptlets","category-the-advanced-capabilites","tag-advanced","tag-forms"],"_links":{"self":[{"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/posts\/2860","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/comments?post=2860"}],"version-history":[{"count":5,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/posts\/2860\/revisions"}],"predecessor-version":[{"id":7336,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/posts\/2860\/revisions\/7336"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/media\/5692"}],"wp:attachment":[{"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/media?parent=2860"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/categories?post=2860"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ioninteractive.com\/ionacademy\/wp-json\/wp\/v2\/tags?post=2860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}