onlygoodness LiteCart Fan From Netherlands Member since Nov 2020 onlygoodness Dec 20 2023 04:29 PM Hi, I tried to get the CAPTCHA on the newsletter register box to use Google V2, because i think it's nicer, but got stuck a little. Used the code on the other CAPTCHA's but i think i missed something. This is the code so far: <operation method="replace" type="multiline" onerror="warning"> <find><![CDATA[ <?php echo functions::form_draw_captcha_field('captcha', 'newsletter_subscribe', 'required'); ?> ]]></find> <insert><![CDATA[ <?php echo functions::recaptcha_draw(); ?> ]]></insert> </operation> </file> <file name="pages/newsletter.inc.php"> <operation method="replace" type="multiline" onerror="warning"> <find><![CDATA[ if (settings::get('captcha_enabled')) { $captcha = functions::captcha_get('newsletter_subscribe'); if (!$captcha || empty($_POST['captcha']) || $captcha != $_POST['captcha']) { throw new Exception(language::translate('error_invalid_captcha', 'Invalid CAPTCHA given')); } } ]]></find> <insert><![CDATA[ if (empty($_POST['g-recaptcha-response']) || !functions::recaptcha_validate($_POST['g-recaptcha-response'])) { throw new Exception(language::translate('error_invalid_captcha', 'Invalid CAPTCHA')); } ]]></insert> </operation> </file>```
tim Founder From Sweden Member since May 2013 tim Dec 20 2023 05:27 PM There is nothing wrong with your code. The problem is the form is fetched partially from the newsletter page via AJAX. Causing the Google reCAPTCHA library not to load as it resides outside the partial content. If you visit the direct URL /newsletter in the browser this probably works as expected? I have tried to make the script tag code stick within the partial content on the page. But it is seems stripped by either Featherlight or jQuery. I have no easy workaround just now. This requires some trial and error to find a solution that works.
tim Founder From Sweden Member since May 2013 tim Dec 20 2023 05:55 PM I found a solution by adding an afterOpen event to Featherlight to load the library. See the new download.
onlygoodness LiteCart Fan From Netherlands Member since Nov 2020 onlygoodness Dec 20 2023 07:12 PM Thanks Tim, I've got a working version for the product reviews also if you like.
tim Founder From Sweden Member since May 2013 tim Dec 20 2023 09:06 PM Sure, just post it here and I will add it.
onlygoodness LiteCart Fan From Netherlands Member since Nov 2020 onlygoodness Dec 20 2023 09:21 PM ok, here it is: <operation method="replace" type="multiline" onerror="warning"> <find><![CDATA[ if (settings::get('captcha_enabled')) { $captcha = functions::captcha_get('review_product'); if (empty($captcha) || $captcha != $_POST['captcha']) throw new Exception(language::translate('error_invalid_captcha', 'Invalid CAPTCHA given')); } ]]></find> <insert><![CDATA[ if (empty($_POST['g-recaptcha-response']) || !functions::recaptcha_validate($_POST['g-recaptcha-response'])) { throw new Exception(language::translate('error_invalid_captcha', 'Invalid CAPTCHA')); } ]]></insert> </operation> </file> <file name="includes/templates/default.catalog/views/box_product_reviews.inc.php"> <operation method="replace" type="multiline" onerror="warning"> <find><![CDATA[ <div style="max-width: 250px;"><?php echo functions::form_draw_captcha_field('captcha', 'review_product', 'required'); ?></div> ]]></find> <insert><![CDATA[ <div style="max-width: 250px;"><?php echo functions::recaptcha_draw(); ?></div> ]]></insert> </operation> </file>```
tim Founder From Sweden Member since May 2013 tim Dec 20 2023 10:34 PM Thank you, I added it. Do you like the new vMod system and the editor in Admin -> vMods -> Edit vMod?
onlygoodness LiteCart Fan From Netherlands Member since Nov 2020 onlygoodness Dec 20 2023 10:56 PM Yeah, I think that's great!
onlygoodness LiteCart Fan From Netherlands Member since Nov 2020 onlygoodness Dec 25 2023 10:40 PM He Tim, The product Review code Re Captcha is a paid add on, won't you get a error if it's not installed?
tim Founder From Sweden Member since May 2013 tim Dec 25 2023 11:55 PM @onlygoodness, no vMod only operates on loaded resources. Sort of an on demand design. :) If the platform is not loading the review components. It's simply ignored.