The issue here lies in the usage of event.preventDefault()
. It should be placed at the beginning of the event handler and not within the submitHandler
. The submitHandler
is a method provided by the jQuery Validate plugin, not by jQuery's event system. In this case, you do not actually have direct access to the event object for the submit event, so calling event.preventDefault()
will not work.
Here's how you can modify your code to correctly use event.preventDefault()
:
$(".commentForm").on('submit', function(event) {
event.preventDefault();
var form = $(this);
if (!form.valid()) return; // You should add validation here