Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a design pattern in the building of website validation with JS and PHP?

For example, I want avoid errors if someone disables Javascript... I think my JS validation must be called by my PHP code...

I'd like know about design patterns or anti-design patterns.

I should clarify that I must use JS in my project and not tools like jQuery or Dojo

like image 247
omar Avatar asked Dec 27 '25 14:12

omar


1 Answers

The problem is more often how to keep both validation identical on the client using JS and on the server using PHP. What i often do is i create my validation on the server only using PHP and i send the content through AJAX using jquery.

The server sees that request as an ajax request because i pass it a content-type and then it doesn't process anything, just validates and returns a JSON response saying everything is ok, or it sends back the error messages that jquery will have to show to the user.

Like you asked, it's only a design pattern, a way of doing. Implementing it is another story, there are tons of ways to do it.

Good luck

like image 166
Mathieu Dumoulin Avatar answered Dec 31 '25 05:12

Mathieu Dumoulin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!