I'm working on a Kentico app V12 (after the same code will be deployed to other installations from 12 to 7) and I added a new form control. In my case the control is for the Google Recaptcha V3 token (so I don't need to save the value), so these are my steps:
- I added the new form control through the Kentico interface
- I added a new field in one form to test the functionality
- I added the Javascript part to manage the recaptcha validation
Actually I'm able to manage all the flow on the client side, my goal now it's validate the token before saving the data, so I added this code on my ascx file
public partial class CMSModules_ReCAPTCHA : FormEngineUserControl
{
private static string GOOGLE_RECAPTCHA_LIBRARY_URL = "https://www.google.com/recaptcha/api.js";
public override bool IsValid()
{
return this.Validate();
}
public override object Value
{
get
{
// How can I get the value?
}
set { }
}
private bool Validate()
{
// Here's the code to validate the token
}
}
If I send the form I can see on the inspector that the token is sent, but how can I get that value on my ascx file and get an error message if the validation is not successful?
I tried with CMS.Helpers.ValidationHelper.GetString(Form.GetFieldValue("reCAPTCHA"))
but it's not working.
reCAPTCHA it's the field's name, the value is sent as g-recaptcha-response.