Do I have to display specific error message for each error in PHP script(these error messages are included in Javascript code)
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 p开发者_运维知识库roblem?
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?
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.
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.
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.
精彩评论