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?
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.