Welcome Guest, Not a member yet? Register   Sign In
client side validation using jquery
#1

[eluser]padma6[/eluser]
I am new to codeigniter framework and jquery also.

I am trying to do client side validations using jquery and downloaded jquery.js and jquery.validate.js.

I have worked on example outside the codeigniter framework it is working fine. But if i placed inside framework then while submitting the form, error messages are displaying and fine till now.But again if i click on submit then error messages are appending to previous errors.

Suppose, please enter username.
again clicking on submit
please enter username.please enter username.

Please someone suggest the solution. Thanks in advance.
#2

[eluser]LuckyFella73[/eluser]
How to help without seeing any code?
#3

[eluser]padma6[/eluser]
js/jquery.js
js/jquery.validate.js

[removed]
$(document).ready(function() {
$("#login_form").validate({
rules: {
username: {
required: true,
minlength: 2
},
password: {
required: true,
minlength: 5
},
},
messages: {
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
}
}
});
});
[removed]

<form action="" id="login_form" name="login_form" method="post">
<input type="text" name="username" value="">
<input type="password" name="password" value="">
</form>
#4

[eluser]LuckyFella73[/eluser]
I set up the jquery validation by getting the .js files from
jquery.com and took the code from your post - everything
works fine (implemented in codeigniter). Maybe you have an error
in the lines you didn'd post. Here is my code for you to compare:

load url helper in controller file

view file:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /&gt;
&lt;title&gt;jQuery validation&lt;/title&gt;

<s-c-r-i-p-t src="&lt;?php echo(base_url());?&gt;jquery.js" type="text/javascript"></s-c-r-i--p-t>
<s-c-r-i-p-t src="&lt;?php echo(base_url());?&gt;jquery.validate.js" type="text/javascript"></s-c-r-i-p-t>

<s-c-r-i-p-t type="text/javascript">
$.validator.setDefaults({
    submitHandler: function() { alert("submitted!"); }
});

$().ready(function() {
  $("#login_form").validate({
      rules: {
        username: {
          required: true,
          minlength: 2
        },
        password: {
          required: true,
          minlength: 5
        },
      },
      messages: {
        username: {
          required: "Please enter a username",
          minlength: "Your username must consist of at least 2 characters"
        },
        password: {
          required: "Please provide a password",
          minlength: "Your password must be at least 5 characters long"
        }
      }
  });
});

</s-c-r-i-p-t>
&lt;/head&gt;
&lt;body&gt;



&lt;form action="" id="login_form" name="login_form" method="post"&gt;
&lt;input type="text" name="username" value=""&gt;&lt;br />
&lt;input type="password" name="password" value=""&gt;&lt;br />
&lt;input class="submit" type="submit" value="Submit"/&gt;

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

Hope you find the error


EDIT:
I just noticed that the script does not work in IE 7. Having a look at
the code I found an error in the js rules section:
Remove the "," after closing the "password" rules.
"}," -> "}"
#5

[eluser]padma6[/eluser]
Thank you. The problem is placing of &lt;form&gt; tag.

<tr>&lt;form&gt;&lt;td><table></table></td>&lt;/form&gt;&lt;/tr>.
and replaced with
<tr><td>&lt;form&gt;&lt;table></table>&lt;/form&gt;&lt;/td>&lt;/form&gt;&lt;/tr>.
Now it is working fine in firefox.

and also i have removed ',' and it is working now also in IE7.

Thank you once again.
#6

[eluser]LuckyFella73[/eluser]
Nice to hear you code is working now!
I still wonder why the error messages
"doubled" themself in your first attempt ..




Theme © iAndrew 2016 - Forum software by © MyBB