I am having a little bit of trouble understanding how to implement jQuery Validation Plugin . With my form that is being submitted with Ajax:
$(document).delegate("'#submit-quote'", "submit", function(){
var quoteVal = $(this).find('[name="quote"]').val();
$.post("add.php", $(this).serialize(), function(data) {
var like = $('.quote-wrap span iframe');
$('.inner').prepend('<div id="' + data + ' " class="quote-wrap group">' + like + '<div class="quote"><p>' + quoteVal+ '</p></div></div>');
// console.log("success");
var id = parseInt(data);
console.log(id)
// some code after being successfully sent
});
After adding validation plugin, how would I set the defaults and make sure it's what I want the form to do?
It's just a textarea, that a user submits a simple quote. (text and numbers) and shouldn't submit anything else. Right now I can submit HTML, or anything else I like.
What do I need to do to make sure the user can't?
I have tried:
If all you need to do is make sure users can't post HTML, then check out this article on StackOverflow: HTML-encoding lost when attribute read from input field .
Otherwise, you can use jQuery Validation to perform a similar method during validation.
try this
$("#myform").validate();
$("a.check").click(function () {
if ($("#myform").valid()) {
//if valid do form submit
}
else {
return false;
}
});
you can check the validity of the form . if valid do your work . else return false,
check this
http://docs.jquery.com/Plugins/Validation/valid
and one more thing, you are using submit
event of the form. that causes page refresh. so you have to
return false OR use http://api.jquery.com/event.preventDefault/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.