I am creating a popup jquery ajax comment form using the jquery validation plugin. Currently, the ajax is returning “this field is required” under the html form fields. How can I get the jquery to return this response inside the form fields as a blur/focus event?
Here is the js that controls the event:
<script>
$(document).ready(function() {
$('#commentForm').validate({
submitHandler: function(form) {
$.ajax({
type: 'POST',
url: 'process.php',
data: $(this).serialize(),
success: function(returnedData) {
$('#commentForm').append(returnedData);
}
});
return false;
}
});
});
</script>
The html form is configured like:
<form class="cmxform" id="commentForm" method="POST" action="">
<p>
<label for="cname">Name</label>
<input id="cname" type="text" name="name" size="60" class="required" minlength="2" />
</p>
<p>
<label for="cemail">E-Mail</label>
<input id="cemail" type="text" name="email" size="60" class="required email" />
</p>
<p>
<label for="curl">URL</label>
<input id="curl" type="text" name="url" size="60" class="url" value="" />
</p>
<p>
<label for="ccomment">Your comment</label>
<textarea id="ccomment" type="text" name="comment" cols="72" rows="8" class="required"></textarea>
</p>
<p>
<div id="button2"><input class="submit" id="submit_btn" type="submit" value="Send Email"/></div>
</p>
</form>
Thank you.
To solve this problem, I used a combination of the errorPlacement and fadeOut functionalities in jQuery. This is the working solution: