So I have a single page which has two language translations, one in Romanian and the other in English. The 2 translations are activated/served in the page using a jQuery button of adding an 'active' class to the translation's respective divs (without refreshing the page).
I am using jQuery Form Validation plugin to validate the forms. The form validation works perfectly fine on the Romanian translation (default view when a user lands on the page). The main problem is that when a user clicks on the translation button to activate the English version, then supplies the form, grecaptcha.getResponse() returns empty, causing my English form validation to not submit.
Below are my codes:
Romanian Form:
<form action="forms/contact-form-handler.php" method="POST" UTF-8 id="ro-form">
<div class="columns is-variable is-2 is-multiline">
<div class="column is-half">
<input class="input" type="text" name="name" placeholder="Nume si prenume" id="ro-name">
</div>
<div class="column is-half">
<input class="input" type="email" name="email" placeholder="Email" id="ro-email">
</div>
<div class="column is-half">
<input class="input" type="text" name="phone" placeholder="Telefon" id="ro-phone">
</div>
<div class="column is-half">
<input class="input" type="text" name="budget" placeholder="Buget">
</div>
<div class="column is-full">
<textarea class="textarea" name="message" placeholder="Message" id="ro-message"></textarea>
</div>
<div class="column is-half">
<div class="g-recaptcha" data-sitekey="my_key_here"></div>
<input type="hidden" class="hiddenRecaptcha required" name="hiddenRecaptcha" id="hiddenRecaptcha">
<button type="submit" class="button is-warning"><span class="send-btn">Send message</span></button>
</div>
</div>
</form>
English Form:
<form action="forms/contact-form-handler.php" method="POST" UTF-8 id="en-form">
<div class="columns is-variable is-2 is-multiline">
<div class="column is-half">
<input class="input" type="text" name="name" placeholder="Name">
</div>
<div class="column is-half">
<input class="input" type="email" name="email" placeholder="Email" id="en-email">
</div>
<div class="column is-half">
<input class="input" type="text" name="phone" placeholder="Phone">
</div>
<div class="column is-half">
<input class="input" type="text" name="budget" placeholder="Budget">
</div>
<div class="column is-full">
<textarea class="textarea" name="message" placeholder="Message"></textarea>
</div>
<div class="column is-half">
<div class="g-recaptcha" data-sitekey="my_key_here"></div>
<input type="hidden" class="hiddenRecaptcha required" name="hiddenRecaptcha" id="hiddenRecaptcha">
<button type="submit" class="button is-warning"><span class="send-btn">Send message</span></button>
</div>
</div>
</form>
jQuery Validation Instance:
$(function() {
// Validate Romanian Form
$("#ro-form").validate({
ignore: ".ignore",
rules: {
name: "required",
phone: "required",
email: {
required: true,
email: true
},hiddenRecaptcha: {
required: function () {
if (grecaptcha.getResponse() == '') {
return true;
} else {
return false;
}
}
}
},
messages: {
name: "Please enter your name",
phone: "Please enter your phone number",
email: "Please enter a valid email address"
},
submitHandler: function(form) {
form.submit();
}
});
// Validate Romanian Form
$("#en-form").validate({
ignore: ".ignore",
rules: {
name: "required",
phone: "required",
email: {
required: true,
email: true
},hiddenRecaptcha: {
required: function () {
if (grecaptcha.getResponse() == '') {
return true;
} else {
return false;
}
}
}
},
messages: {
name: "Please enter your name",
phone: "Please enter your phone number",
email: "Please enter a valid email address"
},
submitHandler: function(form) {
form.submit();
}
});
});
Thank you for the help.