Hi @fitnsexy!
The best way to exclude the code script is by enqueuing it as an external script using wp_enqueue_script. For example, you can have your code in wp-content/uploads/my_files/my_script.js. Then, using wp_enqueue_script() as described below, your custom external script will be applied to the footer section of your site
function enqueue_custom_jquery_script() {
$script_url = content_url('uploads/my_files/my_script.js');
wp_enqueue_script('my-custom-script', $script_url, array('jquery'), null, true );
}
add_action('wp_enqueue_scripts', 'enqueue_custom_jquery_script');
With that, you can exclude your JavaScript file by adding wp-content/uploads/my_files/my_script.js to the Exclude JavaScript from processing field at WP-Optimize > Minify > JavaScript.
With that, your forms should work as expected.
Let us know if that works for you.
Regards.
Thx @deabiodun
Where do I have to enter the code above?
function enqueue_custom_jquery_script() {
$script_url = content_url('uploads/my_files/my_script.js');
wp_enqueue_script('my-custom-script', $script_url, array('jquery'), null, true );
}
add_action('wp_enqueue_scripts', 'enqueue_custom_jquery_script');
You can use a code snippet plugin or paste it in your themes functions.php file.
Note that you could loose the code with the theme approach, when the theme gets updated. So consider using a child theme.
Regards.
Allright, thx for your support @deabiodun
If anyone is interested, I created a JS file with the following code:
/**
* Disable the Enter key WPForms forms
*
* @link https://wpforms.com/developers/how-to-stop-the-enter-key-from-submitting-the-form/
*/
jQuery(function($) {
$('form.wpforms-form').on('keydown', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
}
});
});
and placed it in a “custom-js” folder in my theme, then created a snippet like this:
/** Disable the Enter key WPForms forms */
function wpf_enqueue_disable_enter_script() {
// Prüfen, ob WPForms aktiv ist
if (function_exists('wpforms')) {
// Script registrieren und laden
wp_enqueue_script(
'wpf-disable-enter', // Handle
get_template_directory_uri() . '/custom-js/wpforms_disable-enter.js', // Pfad zur JS-Datei
['jquery'], // Abhängigkeit
null, // Version (optional)
true // Im Footer laden
);
}
}
add_action('wp_enqueue_scripts', 'wpf_enqueue_disable_enter_script');