D
D
darksladen2017-03-05 13:10:03
PHP
darksladen, 2017-03-05 13:10:03

How to properly validate forms?

For a long time I was looking for how to do validation, but I did not find what I needed. I am interested in the correct validation on medium-sized sites, as well as on landing pages (I wonder if the validation methods differ at all depending on the scale of the project). Now about everything in order.
Firstly, how correct would it be to make a single validation logic for the entire site? Those. make handlers for the fields and hang them on the class or on the name attribute (how much is it right to hang on name, and not id, for example, and why), so that validation is applied throughout the site. I talked with an experienced developer and he said that they do validation for each form (why??? After all, you can forget about some field for example =)), and that assigning id fields is cool (it’s also very interesting why, because id in fact, it’s generally a bad tone and what if there are 2 identical forms on page 1 .. Then the second one will also have to do other id).
2. Is it good to use js plugins or is it better to do it yourself, again, according to a cool developer, it's EASIER to do it yourself .. What do you say?
3. How is the response from the server usually handled? Now I send a request to the controller (I use laravel) and pass the status to the view, depending on which different messages are displayed. Those. in case of an error, the server gives a view with an error. Is it better to do this or send some kind of status to the client so that it can be processed there on js?
If you have read it, then thank you very much =) I will be glad to have any thoughts!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Bogachev, 2017-03-05
@darksladen

they do validation for each form (why??? After all, you can forget about some field, for example =))

Validation - that's what validation is for, you need to check everything.
Umm... what? In styles - yes, it's bad, but not in scripts.
This is problem? It seems not.
Validation on the client is a regular expression + some reaction to the correctness / incorrectness of the user's actions. Writing by hand is often really easier and faster than rewriting the finished one.
From a UX point of view, you should (if the user made a mistake) immediately show him an error in the spirit of "hey guy, your password is shorter than eight characters" and highlight the form with the password ( example ). And don't send anything to the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question