Redirection in contact 7 form plugin after submission of form in wordpress
Explore our JavaScript category, where you’ll find loads of helpful articles and tutorials for everyone, whether you’re just starting out or a pro developer. Learn about different JavaScript functions that can be used in various projects according to their specific requirements.
JavaScript snippet that uses the addEventListener function to listen for a specific event, in this case, the ‘wpcf7mailsent‘ event. This event is typically associated with the Contact Form 7 WordPress plugin when a form submission is successful.
document.addEventListener(‘wpcf7mailsent’, function(event) {
location = ‘https://example.com/’;
}, false);
location = ‘https://example.com/’;
}, false);
- document.addEventListener: This function is used to register an event listener on the document object.
- wpcf7mailsent This is the event type. It indicates that the listener will be triggered when the 'wpcf7mailsent' event occurs.
- The second argument is an anonymous function that will be executed when the 'wpcf7mailsent' event is fired. In this case, it redirects the user to the URL 'https://example.com/' using location = 'https://example.com/';.
- The third argument (false) is the useCapture parameter. In this case, it is set to false, indicating that the event should be handled in the bubbling phase rather than the capturing phase.
In summary, when the ‘wpcf7mailsent’ event occurs (indicating a successful form submission), the user’s browser will be redirected to ‘https://example.com/’.