Unite PHP and javascript?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
heiatufte
Forum Newbie
Posts: 18
Joined: Wed Mar 02, 2005 3:45 pm
Location: AA, Norway

Unite PHP and javascript?

Post 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 :)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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
Post Reply