Reputation: 139
I have a problem regarding in validation in html. I'm using .validate() of the validation plugin but its not working to me. can someone help me from my problem? I have two names in each of my . An array of data i used in inserting in database. Is it conflict? what should I do since it is required that we need to use array in inserting data to the database? I already try to put "#" and "data[0]" in my rules to look for the but still not worked.
Note: the validation.js served as my validation plugin which i've downloaded online. jQuery Validation Plugin 1.11.1. And the jquery.js served as JQuery 1.8.3.
Here's my code.
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>
<script src="loginBouncy.js"></script>
<script src="modal.js"></script>
<script type="text/javascript" src="validation.js"></script>
<script src="validate.js"></script>
<form id="mainform" name="mainform" method="post" action="SignUp2.php">
<input type="text" name="data[]" id="fname" name="fname" placeholder="First Name"/>
<input type="text" name="data[]" id="lname" name="lname" placeholder="Last Name"/>
<input type="text" name="data[]" id="mname" name="mname" placeholder="M.I."/>
<input type="text" name="data[]" id="sadd" name="sadd" placeholder="Street"/>
<input type="text" name="data[]" id="tadd" name="tadd" placeholder="Town/City"/>
<input type="text" name="data[]" id="padd" name="padd" placeholder="Province/State"/>
<input type="text" name="data[]" id="user2" name="user2" placeholder="Your Username"/>
<input type="password" name="data[]" id="pass2" name="pass2" placeholder="Your Password">
<input id="captcha" name="captcha" type="text" name="captcha" placeholder="Insert Captcha">
<img id="imgcaptcha" src="captcha.php" /><br>
<input type="text" name="data[]" id="email" name="email" placeholder="Your Email"/>
<input type="button" id="btnSignUp" placeholder="" onclick=""/>
</input>
<p id="confirm" style="font-size:15pt; position:absolute; top:450px; left:850px; ">dfgfdgdf</p>
</form>
</html>
my validate.js
$(document).ready(function(){
$('#btnSignUp').click(function(){
$('#mainform').validate({
rules:
{
fname:
{
required: true,
minlength: 7
}
},
success: function(){
alert("valid");
}
});
});
});
Upvotes: 0
Views: 79
Reputation: 388316
There are multiple problems.
The validator uses name of the input field, you have 2 name attributes in the input field remove name="data[]"
, it should be like <input type="text" id="fname" name="fname" placeholder="First Name" />
The validation is automatically applied on form submit event so change btnSignUp
to type="submit"
<input type="submit" id="btnSignUp" placeholder="" value="Sign Up" />
Also the validate framework should be initialized on dom ready, not in a click handler
jQuery(function ($) {
$('#mainform').validate({
rules: {
fname: {
required: true,
minlength: 7
}
},
success: function () {
alert("valid");
}
});
$('#btnSignUp').click(function () {
});
});
Demo: Fiddle
Upvotes: 1