Solution:
You could use jQuery to check if any of your comment form input
elements are empty, and if they are, display an error message and prevent the form from submitting.
Using #email
and #author
as example input
elements, you could do something like this (not tested):
$('#form').submit(function() {
if ($.trim($("#email").val()) === "" || $.trim($("#author").val()) === "") {
alert('you did not fill out one of the fields');
return false;
}
});
You could take it a step further by showing an element within the comment form instead of a browser alert pop up.
Using a hidden element in your comments form markup:
<div class="error-message" style="display:none">custom error message here</div>
Then show that message when the fields are empty like this:
$('#form').submit(function() {
if ($.trim($("#email").val()) === "" || $.trim($("#author").val()) === "") {
$(".error-message").fadeIn();
return false;
}
});