If you search on the internet about How to Stop the Enter Key from Submitting the Form, you will find some jQuery solutions.
Those solutions are good. But the problem is that maximum solutions will prevent users from hitting the enter button in the textarea. So users won’t be able to create a new line in the comment section.
And the main problem is that those solutions are dependent on jQuery.
Some of your pages may have jQuery loaded, and some may not. Running jQuery on those pages just to disable the enter key is not a good idea. Or you may not use jQuery at all.
So I have discovered pure JavaScript to do that. Here it is:
add_action('wp_footer', 'dgwt_disable_form_submit_on_enter', 99);
function dgwt_disable_form_submit_on_enter(){ ?>
<script>
document.onkeypress = function(evt) {
if(evt.target.toString() !== '[object HTMLTextAreaElement]' && evt.charCode === 13){
evt.preventDefault();
return;
}
};
</script>
<?php }
Paste this code into your theme’s functions.php file.
Let me know in the comment section if it works or not.