VALIDATE- REMOTE METHOD
by bizamajig
HTML
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<form id="form-switcher--login" name="form-switcher--login" action="entrance-public-login.asp" method="POST" class="xxx-form-signin collapse fade in active">
<fieldset class="ui_webform_block bg-white card-block container">
<div class="row">
<div class="col-xs-12">
<div class="form-group field">
<input type="text" class="form-control auto-focus element-top" name="username" id="username" value="vinnies" required="" placeholder="Email or username" autofocus="">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="form-group field">
<input type="password" class="form-control element-bottom" name="password_text" id="password_text" placeholder="Password" required="">
</div>
</div>
</div>
<div class="buttons pull-none">
<input type="submit" name="Sign in" id="Sign in" class="m-t-10 btn btn-info btn-xs btn-block" value="Sign in">
</div>
<a href="#form-switcher--password-reminder" rel="#form-switcher--password-reminder" data-target="#form-switcher--password-reminder" class="m-center m-t-20 d-table form-switcher-link">
Forgot username or password?
</a>
</fieldset>
</form>
<form class="form-horizontal form-validate" action="#" method="post">
<input type="hidden" name="formIdentifier" value="addDel" />
<div class="form-group">
<div class="col-sm-3">
<input type="text" name="delivery_Method" class="form-control" placeholder="Enter new method" />
</div>
<div class="col-sm-2 col-sm-offset-2">
<button type="submit" class="btn btn-default btn-block">Add</button>
</div>
</div>
</form>
JavaScript
$(document).ready(function () {
$('#form-switcher--login').validate({
onkeyup: false, rules: {
password_text: {
remote: {
url: '/MyController/CheckValue',
type: 'POST',
data: {
password: $( '#password' ).val(),
value: 'lllllllllllllll'
}
}
}
},
messages: {
password: {
remote: 'This value is not valid'
}
},
submitHandler: function(form){
alert('here');
}
});
$('.form-horizontal').each(function () {
$(this).validate({
onkeyup: false, rules: {
delivery_Method: {
required: true,
remote: {
type: 'post', // the method you are going to use to send the data
url: '/entrance-public-section.asp', // our remote url for validating
dataType: 'json',
data: { // the data we are going to send for verification
password: function() {
return $( '#password' ).val(); // send the value of email
}
}
}
}
},
message: {
delivery_Method: {
required: true
}
}
});
});
});