onlygoodness LiteCart Fan Dari Netherlands Anggota sejak Nov 2020 onlygoodness 20 Des 2023 16:29 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 Dari Sweden Anggota sejak Mei 2013 tim 20 Des 2023 17:27 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 Dari Sweden Anggota sejak Mei 2013 tim 20 Des 2023 17:55 I found a solution by adding an afterOpen event to Featherlight to load the library. See the new download.
onlygoodness LiteCart Fan Dari Netherlands Anggota sejak Nov 2020 onlygoodness 20 Des 2023 19:12 Thanks Tim, I've got a working version for the product reviews also if you like.
tim Founder Dari Sweden Anggota sejak Mei 2013 tim 20 Des 2023 21:06 Sure, just post it here and I will add it.
onlygoodness LiteCart Fan Dari Netherlands Anggota sejak Nov 2020 onlygoodness 20 Des 2023 21:21 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 Dari Sweden Anggota sejak Mei 2013 tim 20 Des 2023 22:34 Thank you, I added it. Do you like the new vMod system and the editor in Admin -> vMods -> Edit vMod?
onlygoodness LiteCart Fan Dari Netherlands Anggota sejak Nov 2020 onlygoodness 20 Des 2023 22:56 Yeah, I think that's great!
onlygoodness LiteCart Fan Dari Netherlands Anggota sejak Nov 2020 onlygoodness 25 Des 2023 22:40 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 Dari Sweden Anggota sejak Mei 2013 tim 25 Des 2023 23:55 @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.