Custom Field Recaptcha version 2
Kentico 10 supports very nicely Google ReCaptcha version 1.
Because Google tagged version 1 is obsolete and in web master tools, you can generate only keys for version 2, we decided to implement a custom form control for Recaptcha version 2.
We have cloned Kentico Captcha selector defining another source file for it.
Keep in mind Kentico Best practice to create separate folders for you custom code: custom modules, custom web parts, custom form controls. Call the name of the folder distinct from CMS, Kentico…etc. We ussualy use project/client name 😊
Now, back to implementing custom code that renders Googles Captcha – I am not a robot.
Same as Kentico does with ReCaptcha, we have implemented a custom web control with two custom properties required for google captcha: private key and public key.
In the render contents method we register Google scrips and html:
The only thing left is no implement a public method we can call from Kentico custom form control code that returns if captcha control is valid.
In Kentico, we need to alter the cloned code for our custom FormControl.
First we need to replace cms:Recapctha with our custom control, implemented earlier.
In the code behind, clean-up what is not relevant for our control.
Validation will be made differently, but simple. Just call captcha control public method, validate, or return its output.
Finally yet importantly, do not forget to set up Google keys for your custom control. In this case, we read Kentico default settings for Google ReCaptcha. New custom settings fields can be created, but that in another post 😊