Page 1 of 1

Unite PHP and javascript?

Posted: Wed Mar 02, 2005 7:42 pm
by heiatufte
Hello and thanks for reading my post :D
I'll try to keep it short:
I have a form. Some specific values are not allowed to be entered (because they're already registered), and these are checked when user presses Submit in a Javascript, and returns true or false, if false, it gives an error message, if true, the form is sent and some other coding comes. This works fine.
However, the same form is using when an existing user is updating his/hers account. But if he/she wants to change only some fields, and not the one which cannot contain already registered names, he/she gets an error!
How can I prevent this?
I hope I made myself clear enough, if not, please let me know :)

Posted: Wed Mar 02, 2005 7:50 pm
by timvw
you don't want to unite them.

first writeyour scripts so that they work without javascript.
in your case you would have to return the same form, with an error message for the field(s) that are invalid (fe: not unique)

once you have done this, you can play with javascript to do the same checks... because javascript can't look directly what is already in the database you will probably have to use xmlhttprequest (http://jpspan.sf.net is nice) to verify that...

notice that the javascript validation would probably less efficient: first an xmlhttprequest to validate the data. then post the data and process them again... = double work