I have an answer to my registration form. The user must enter something in the recaptcha field before he is sent to the server. I have server side validation and client side validation for other fields.
Generated html from rcaptcha:
<input type="text" id="recaptcha_response_field" name="recaptcha_response_field" autocomplete="off" class="valid">
View:
@ReCaptcha.GetHtml(theme: "red", publicKey: GetPublicKey()) @Html.ValidationMessageFor(m => m.recaptcha_response_field)
Model:
[Required(ErrorMessage = "'captcha required' ")] public string recaptcha_response_field { get; set; }
When loading, I see the message "captcha required". But if I print something, it still appears. The form is sent with an empty recaptcha box.
How can I do the required recaptcha field on the client side?
thanks for the help
EDIT: I added this to catch the submit btn click event, but does not stop sending the form.
<button type="submit" id="btnSubmit" class="sprt bg_red bt_red h25" onsubmit="ValidateAndSubmit();">Signup</button> <script type="text/javascript"> function ValidateAndSubmit() { var v=$('#recaptcha_response_field').val(); if (v == '' || v == undefined) { alert('captcha is required'); return false; } return true; } </script>
kheya source share