how to check email exist with Jquery and ajax? |
[eluser]Kency[/eluser]
Hi everybody i try to check email exists with Jquery and codeigniter but i can't do it my jquery code Code: //check email and my controller Code: public function checkemail($email){ and my model Code: function checkusername($username) my view: Code: <div class="formRow"> and my problem is when i enter email address into text field, it just show preloader and it can't check email exist or not i know codeigniter prevent @ in uri (because my code will show uri like admin/user/checkemail/[email protected]) but i try to use another way, but it not work too i change my code to Code: $('#email').blur(function(){ my controller Code: public function checkemail(){ but i got no result and preloading still load @.@ please help me!
[eluser]Silviu[/eluser]
Indeed, CI allows (by default) only certain characters in the URL. You can change those characters in your application config file. However, my suggestion is to simply use POST when sending your AJAX request. Should be something along these lines in your script: Code: $.ajax({ Code: public function checkemail(){ Give it a shot, see how it goes.
[eluser]Kency[/eluser]
@Silviu thank for ur reply but i change a little bit of your answer and it work well Thank you Code: data : "email="+email,
[eluser]Kency[/eluser]
I have problem when i try to prevent user submit if it check is username or password exits i try using return false for Ajax section but when user enter right email and not exist in db form cannot submit, can u help me @Silviu Thank you very much
[eluser]Silviu[/eluser]
*** Note ***: You cannot really prevent a user submitting a form. All it has to do is to disable JS in the browser. To stop a form from being submitted, you must "return false" on the form's onsubmit event. Code: <form on+submit="checkFields()"> As noted before, this is not a safe way to accept user input. To be sure, you must re-check the data in the method that receives and processes the input.
[eluser]nl_vinyl[/eluser]
Why don't you make a custom validation rule that handles this for you? As soon as it validates and the rule is "false" then the form won't submit. Not only is this server side code, so it does not depend on javascript it also keep everything in one place. And it is not a great idea to use javascript in your form itself. Use jQuery with a "onsubmit" event. That way you keep you code clean and separated. A better way to send the data is to not do it in the URL but just send it with jQuery as post data and handle that in a controller. Also be sure to validate the post data to prevent nasty stuff. |
Welcome Guest, Not a member yet? Register Sign In |