The WordPress NinjaForms plugin provides a JavaScript API that can be used to extend its functionality. If you want to execute custom code before a form is submitted, you can use the beforeSubmit event provided by the NinjaForms JavaScript API.

Here is an example code snippet that demonstrates how to use the beforeSubmit event to execute custom code before the form is submitted:

javascript
jQuery(document).ready(function($) { // Get the form element var form = $('#nf-form-1'); // Attach an event listener to the beforeSubmit event form.on('beforeSubmit', function(e) { // Execute custom code before the form is submitted console.log('Before form submit'); // If you want to prevent the form from being submitted, you can call e.preventDefault(); // e.preventDefault(); }); });

In the example above, we are getting the form element with an ID of nf-form-1 and attaching an event listener to the beforeSubmit event. When the event is triggered, the custom code inside the event listener will be executed.

You can use this event to perform any actions you need to do before the form is submitted, such as validating user input or modifying form data. If you need to prevent the form from being submitted, you can call e.preventDefault() inside the event listener.

Have questions or queries?
Get in Touch