form validation with ajax (mail validation) |
[eluser]theighost[/eluser]
hi, I am making a form, i want to check if the mail written in the form is not already used and doesn't exist in the database. I don't want to use any special codeigniter form validation functions. My idea was to make a function with ajax, at the top of the form, this function will apply a controller that will check if the mail is used or not, if its used the controller will 'print' false. a javascript will check the result if is false, if its false then an alert ('the email is used'). this is the controller: Code: function validation() Code: function valid(mail) and then the javascript comes: Code: function checkForm() nothing happens with this script, please help.
[eluser]Pascal Kriete[/eluser]
No framework at all, it's just plain javascript. Just a quick cursory glance: 1. You have 2 typos in your checkForm function: mail not mai, and the parameter for getElementById should be quoted. 2. You don't want to respond to 404s and the like, so the if statement should read: (x.readyState==4 && x.status == 200) Make sure your php script is working as expected by visiting the url directly. If that works, then you can worry about the js.
[eluser]theighost[/eluser]
i've written some of the script by hand in this forum and in a hurry, in the file they are correct. actually i know that the PHP file works and i am worrying about the ajax
[eluser]xwero[/eluser]
Easier than using your own code try using a javascript framework or if you don't want to use a framework use an ajax library like jx. This way there is less chance for a bug to occur when making an ajax request. Check out the request in firebug. That should give you a clue if there is something wrong or not.
[eluser]gurthgor[/eluser]
I recommend you to use Xajax, its quite easy and well documented, you just have to use xajax_functionname(params) in javascript and that loads you a php function where you can check if the email is available or not. You can use it as a library of codeigniter with no problems and add the xajax functions in the controller. |
Welcome Guest, Not a member yet? Register Sign In |