Elena Semenchenko Elena Semenchenko - 1 year ago 72
Javascript Question

I have some problems with jquery-validate

I'm trying to do validation form using jquery-validate plugin:

fitToView : false,
autoSize : false,
closeClick : false,
maxWidth : 502,
maxHeight : 444,
prevEffect : 'none',
nextEffect : 'none',
padding : 0,
margin : 50,
closeBtn : false,
helpers : {
overlay : {
css : {
'background' : 'rgba(0, 0, 0, 0.72)'

// Callback forms

var app = {

init: function(){

setUpListeners: function(){

$(document).on('submit', 'form', this.submitForm);
$(document).on('keyup', 'input', this.removeError);

submitForm: function(e){

var form = $(this),
btnSubmit = form.find('[type="submit"]');

//if(app.validateForm(form) === false) return false;

invalidHandler: function(event, validator){
var errors = validator.numberOfInvalids();
if (errors) {
return false;
btnSubmit.attr('disabled', 'disabled');

} else {

btnSubmit.attr('disabled', 'disabled');

var str = form.serialize();

url: 'contacts.php',
type: 'post',
data: str

if(msg === "OK"){
var res = "<div class=\"alert alert-success\" role=\"alert\"> <strong>Well done!</strong> You successfully read this important alert message. </div>";

}, 2000)


}else {


btnSubmit.removeAttr('disabled', '');

validateForm: function(form){
var inputs = form.find('input'),
valid = true;

// $.each(inputs, function(i, val){
// var input = $(val),
// val = input.val(),
// formGroup = input.closest('.form-row');

// if(val.length === 0){
// formGroup.addClass('has-danger');
// valid = false;
// } else {
// formGroup.addClass('has-success').removeClass('has-danger');
// }

// });

// return valid;

removeError: function(){
var $this = $(this),
formGroup = $this.closest('.form-group');



.callback-modal {
display: none;

<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.1/additional-methods.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.1/additional-methods.js"></script>
<div class="wrap">
<a href="#request" class="modalbox">Оформить заявку</a>

<div id="request" class="callback-modal">
<div class="callback-modal__inner">
<form class="callback__form" id="callbackForm">

<div class="form-row">
<input type="text" name="name" id="r-name" placeholder="Имя" class="input" data-rule-required="true">

<div class="form-row">
<input type="text" name="phone" id="r-phone" placeholder="Телефон" class="input" data-rule-required="true" data-rule-minlength="5">

<div class="form-row">
<input type="text" name="email" id="r-email" placeholder="E-mail" class="input" data-rule-required="true" data-rule-email="true">

<div class="form-row">
<textarea name="msg" id="r-msg" placeholder="Описание сайта" class="input"></textarea>

<input type="submit" value="Отправить" class="btn btn__submit">

<div class="fancybox"></div>



form.validate is not a function

But I can not understand the errors and how to fix them. Maybe someone has worked with this plugin.

How can I fix the module to plug breakdowns and breakdowns as expected (if fields are empty, the form is not sent are displayed error field, if everything is in order, the data is sent)?

Answer Source

"form.validate is not a function" means that the .validate() method is not recognized because you have not included the plugin...

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.1/additional-methods.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.1/additional-methods.js"></script>

You've included the additional-methods.js file twice but failed to include the jQuery Validate plugin once.

Should look like this instead...

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.0/jquery.validate.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.1/additional-methods.js"></script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download