make Google reCaptcha Required Topic is solved

For Joomla! 4.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
neojw1505
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Wed Aug 11, 2021 12:44 pm

make Google reCaptcha Required

Post by neojw1505 » Fri Sep 24, 2021 1:39 pm

I have a registration form that looks like this https://prnt.sc/1tgmzq5. As shown in the picture, I would like to remove the top captcha and just keep the bottom captcha. One thing to note is that the top captcha is created using xml (attached as registration.xml), and the bottom one is created inside my registration folder as default.php. I have attached the snippet responsible for rendering the bottom captcha as recaptcha_btm.txt. (without the site key)

The issue is that the bottom captcha does not validate, it allows the user to register even if the captcha checkbox is not checked and it does not prompt a joomla alert message "Invalid Captcha..." that looks like this https://prnt.sc/1tgpj9v The top captcha that is created inside the xml file does not have any issues, only when I used the bottom captcha, no alert message will be shown. The reason I created the bottom captcha is because I wanted the captcha position to be at the bottom of the webpage; before register button and after term of service.

I have tried to mimic the html code of the bottom captcha to be the same as the upper captcha. But still could not figure out what is the issue.

I hope that some kind souls can help me out here. Thank you for taking the time to read this.
You do not have the required permissions to view the files attached to this post.
Last edited by imanickam on Tue Sep 28, 2021 7:40 am, edited 1 time in total.
Reason: Moved topic » from General Questions/New to Joomla! 4.x to Joomla! 4.x Coding

sterlingcomple
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Wed Sep 01, 2021 10:14 am

Re: make Google reCaptcha Required

Post by sterlingcomple » Fri Sep 24, 2021 6:01 pm

Tell me google captcha is required for joomla website

User avatar
AMurray
Joomla! Champion
Joomla! Champion
Posts: 7133
Joined: Sat Feb 13, 2010 7:35 am
Location: Australia

Re: make Google reCaptcha Required

Post by AMurray » Fri Sep 24, 2021 11:38 pm

I don't quite understand your explanation above.

ReCaptcha is activated via a Plugin in Joomla (with the relevant site and private keys provided through your Google account), or with the snippet of code that Google gives you that would be placed within the index.php file of your template.

In normal circumstances it should not be showing twice in the Registration form. Is that Registration the standard Joomla form, or one that is from your template?
Regards - A Murray

neojw1505
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Wed Aug 11, 2021 12:44 pm

Re: make Google reCaptcha Required

Post by neojw1505 » Mon Sep 27, 2021 12:52 am

AMurray wrote:
Fri Sep 24, 2021 11:38 pm
I don't quite understand your explanation above.

ReCaptcha is activated via a Plugin in Joomla (with the relevant site and private keys provided through your Google account), or with the snippet of code that Google gives you that would be placed within the index.php file of your template.

In normal circumstances it should not be showing twice in the Registration form. Is that Registration the standard Joomla form, or one that is from your template?
What part do you not understand? I believed I already made it very clear.

I know it should not be showing twice. The registration is not a standard joomla form, it is created from the xml file.

User avatar
AMurray
Joomla! Champion
Joomla! Champion
Posts: 7133
Joined: Sat Feb 13, 2010 7:35 am
Location: Australia

Re: make Google reCaptcha Required

Post by AMurray » Mon Sep 27, 2021 2:17 am

The "XML" file bit is what I don't understand; I understand the XML file in this case is defining your form fields, but I don't know why it's necessary to do it the way you've done it.

In normal circumstances, you just activate the Recaptcha plugin, put in the site and private key and specify it as the default Captcha in Global configuration of Joomla.

Perhaps your XML definition file is causing the duplicate?

But if you're not using the actual plugin then you need Google's code snippet that would normally go in the index.php file of your active site template.
Regards - A Murray

neojw1505
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Wed Aug 11, 2021 12:44 pm

Re: make Google reCaptcha Required

Post by neojw1505 » Mon Sep 27, 2021 3:42 am

AMurray wrote:
Mon Sep 27, 2021 2:17 am
The "XML" file bit is what I don't understand; I understand the XML file in this case is defining your form fields, but I don't know why it's necessary to do it the way you've done it.

In normal circumstances, you just activate the Recaptcha plugin, put in the site and private key and specify it as the default Captcha in Global configuration of Joomla.

Perhaps your XML definition file is causing the duplicate?

But if you're not using the actual plugin then you need Google's code snippet that would normally go in the index.php file of your active site template.
Thanks for the quick reply, the duplicate is not the issue I am facing.

The issue that I am facing is that there is no validation if I were to use google code snippet instead of the actual plugin.

I intentionally showed 2 recaptcha in my screenshot to show what I want to change.
I only want to use the google code snippet to render the captcha, but I have added into the registration.php instead of index.php as I want the reCaptcha to be shown in the registration page.

SharkyKZ
Joomla! Ace
Joomla! Ace
Posts: 1999
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: make Google reCaptcha Required

Post by SharkyKZ » Mon Sep 27, 2021 6:20 am

First, you should never modify core files. Your changes will be lost on update. Secondly, fields must be present in the form definition XML. Adding just HTML markup to the layout isn't going to work. That said, this can be done with a plugin by changing captcha field's place in the form. Or with layout override by changing how the form is rendered.

In the layout override change this:

Code: Select all

<?php echo $this->form->renderFieldset($fieldset->name); ?>
to this:

Code: Select all

<?php foreach ($fields as $field) : ?>
	<?php if ($field->type === 'Captcha') : ?>
		<?php continue; ?>
	<?php endif; ?>
	<?php echo $field->renderField(); ?>
<?php endforeach; ?>
This skips captcha field when rendering fields. And then render it manually like this:

Code: Select all

<?php echo $this->form->renderField('captcha'); ?>

neojw1505
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Wed Aug 11, 2021 12:44 pm

Re: make Google reCaptcha Required

Post by neojw1505 » Mon Sep 27, 2021 6:36 am

SharkyKZ wrote:
Mon Sep 27, 2021 6:20 am
First, you should never modify core files. Your changes will be lost on update. Secondly, fields must be present in the form definition XML. Adding just HTML markup to the layout isn't going to work. That said, this can be done with a plugin by changing captcha field's place in the form. Or with layout override by changing how the form is rendered.

In the layout override change this:

Code: Select all

<?php echo $this->form->renderFieldset($fieldset->name); ?>
to this:

Code: Select all

<?php foreach ($fields as $field) : ?>
	<?php if ($field->type === 'Captcha') : ?>
		<?php continue; ?>
	<?php endif; ?>
	<?php echo $field->renderField(); ?>
<?php endforeach; ?>
This skips captcha field when rendering fields. And then render it manually like this:

Code: Select all

<?php echo $this->form->renderField('captcha'); ?>
Hi thank you for the detailed response, however, this would not work as the page is structured like this https://prnt.sc/1tsn36r I would like to make the captcha position to be exactly where it is in the link. However, I only found a way to do that by writing html code in the registration.php page. I am not able to add another captcha field in the User Profile plugin as the plugin does not have a captcha option https://prnt.sc/1tsnrzf

SharkyKZ
Joomla! Ace
Joomla! Ace
Posts: 1999
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: make Google reCaptcha Required

Post by SharkyKZ » Mon Sep 27, 2021 6:40 am

That code is to be added to the registration layout.

neojw1505
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Wed Aug 11, 2021 12:44 pm

Re: make Google reCaptcha Required

Post by neojw1505 » Mon Sep 27, 2021 7:13 am

SharkyKZ wrote:
Mon Sep 27, 2021 6:40 am
That code is to be added to the registration layout.
OMG! You are a lifesaver! thank you so much!! I have been struggling to try to get the captcha to be at the bottom position and still get the Joomla alert validation message. I still don't really understand how I can just detach a captcha field like that and just place it manually where I want it to be. But I am just happy it is working now :)


Post Reply

Return to “Joomla! 4.x Coding”