I have set up google reCaptcha on contact us page but i dont know how to check its mandatory on submit for any other way.
2 Answers
To do so, you need some custom code, please follow below steps which work for me:
Note: I assume you used jQuery library on your frontend theme
Step-1: On document ready add some custom class to your reCAPTCHA
input field:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#recaptcha_response_field').addClass('required-captcha-entry');
})
</script>
Step-2: Initialize Magento
VarienForm
javascript class object and add new validation rule for reCAPTCHA
field:
<script type="text/javascript">
var yourFormValidationObj = new VarienForm('your_form_id');
Validation.add('required-captcha-entry', ' ', function(v) {
return !Validation.get('IsEmpty').test(v);
})
</script>
Step-3: On form submit, validate form for required values
<script type="text/javascript">
if(yourFormValidationObj.validator.validate()){
// Form validate and ready to submit
jQuery('YOUR_FORM_IDENTIFIER').submit();
}
</script>
That's, your reCAPTCHA
field is become required field and validated before submit the form.
You can try this method: Magento Enable Captcha For Contact Us Form
Hope it will help you.
-
-
-
-
-
i have try this but not working form e. not display captcha box. i have already set the both key. Commented Mar 25, 2016 at 11:56