views:

55

answers:

4

I am developing a website using PHP. I use Javascript/jquery to control/regulate user input. Of course I need to validate user input against these rules in PHP script. However, do I have to display specific error messages once an error is detected in PHP script? I mean if the Javascript runs properly, the errors of input won't come out in PHP script. Only when a user disables Javascript or bypasses Javascript somehow can the errors of input come out in PHP script. How to handle this problem?

I know I need to validate user input in PHP script, the problem is that whether I need to display specific error message to a user once an error is detected in PHP script?

+1  A: 

I would say you are the only one who can choose whether or not your website should display specific error messages ;-)


Considering Javascript can be disabled, you should probabbly display specific (useful) error messages -- but, considering it's not often disabled... Well, maybe you have some stuff to do that has a higher priority ?

Which, of course, doesn't prevent you from implementing those specific error messages a bit later, when there's nothing with a higher priority left to do ;-)


In the end, the question you are asking shows you started developping the JS part of your application, and, only in the end, thought about the "what if JS is disabled" part.

In theory, things should go the other way arround :

  • First, develop the website without depending on Javascript
  • And when it's working OK, start enhancing it with Javascript

Which means :

  • Users who have JS enabled will have a nice website
  • And users without Javascript will also have a fully-functionnal website ; even if it's a bit less user-friendly.


Still, what really matters is that you're doing verifications on the server side -- and you are.

Pascal MARTIN
+2  A: 

Well, the problem is that whether Javascript is active or not changes from user to user, while PHP is used across all users, as it is ran before the page even leaves the server.

Ideally, You should always design a site as if you don't have Javascript, and then layered Javascript on as if it was an extra layer of usability. You never know what the user's browser is running, and it is best to design for the worst.

Javascript tends to work best, especially with jQuery, when you simply create a valid website that has the basic features you want, and then you bring in Javascript to make it run without refreshing. You hook Javascript into the page by making submit buttons not refresh, but simply tell Javascript to submit the form, or you have Javascript do error producing instead of the PHP page.

The benefit of designing this way is that because you have made a fully PHP based functioning website, the people that don't have Javascript can still use your website, and the people who do have Javascript get a nicer, cleaner, more usable website.

In some instances, if your audience is very known, like a company application, you can forget about not having Javascript. But with a public website, it is best to design for the worst.

So,yes. I would have PHP display errors just as well as Javascript did.

Chacha102
Normally Javascript is active and does not change from user to user.
Steven
It is a public website.
Steven
If it is a public website, then no, you cannot say that it is always active....
Chacha102
Its really the difference between compatibility (being compatible with NON-JS users) and convenience
Chacha102
A: 

Whether to implement a complete fall-back for non-javascript clients/users or not is an ongoing debate for years and years.
I guess it depends on the clientele you expect for your website and how much afford you want to put in for the (alleged) minority. And there are many shades of not implementing the whole user pampering experience for non-javascript clients. E.g. your server could sent maybe two or three different general error messages while at input time the javascript shows detailed messages.

VolkerK
A: 

Ideally, you should always assume that JavaScript can be disabled/tampered-with and perform error checking on server side. If you are doing that, JavaScript validation might seem redundant but it saves your end-user from frustration.

Salman A