i need to validate if captcha is valid redirect to another page if not show alert("Error")
the action is on a button Click
please help
Hello,
i have done exactly what you explained but no luck i pasted the javascript on the button Click event
any help please !!!
To handle a button click event that includes CAPTCHA validation before submitting the form, you can use the following approach in your Plumsail Form's JS:
JavaScript Code:
fd.rendered(function() {
var buttonControl = fd.control('Button1'); // Replace 'Button1' with your button's name
var captchaControl = fd.control('Captcha1'); // Replace 'Captcha1' with your CAPTCHA's name
if (buttonControl && captchaControl) {
buttonControl.$el.addEventListener('click', function(event) {
event.preventDefault(); // Prevent the default form submission
// Validate CAPTCHA
captchaControl.validate().then(function(isCaptchaValid) {
if (isCaptchaValid) {
alert('CAPTCHA is valid. Proceeding to save...');
fd.save().then(function() {
// Redirect after successful form submission
window.location.href = 'https://your-redirection-url.com';
});
} else {
alert('Error: CAPTCHA is invalid.');
}
});
});
}
});
How It Works:
- Button Click Handling: The script attaches an event listener to your button (
Button1). When clicked, it prevents the default form submission. - CAPTCHA Validation: The CAPTCHA control (
Captcha1) is validated. If valid, the form is saved and the user is redirected; otherwise, an error message is shown. - Redirection: After successful form submission, the user is redirected to the specified URL.
Steps to Implement:
- Replace the Control Names: Ensure you replace
'Button1'and'Captcha1'with the exact names of your controls. - Insert the Script: Add this script to your form's JavaScript editor.
- Test the Functionality: Ensure the CAPTCHA validation and redirection work as expected when the button is clicked.
This should handle the button click and CAPTCHA validation smoothly.
THANK YOU PAUL
THAT WORKS Perfectly.