Peter
Peter

Reputation: 211

Use javascript validation on server

In my LAMP application I am using Javascript for form validation but of course internet users can switch Javascript off in their browser so I also validate the form data on the server using a PHP function.

Does anyone know if there is some clever way to reuse my Javascript validation on the server so as to avoid writing a PHP version?

Upvotes: 1

Views: 99

Answers (2)

kojiro
kojiro

Reputation: 77137

It's a little difficult to tell without knowing how you've constructed your application, but it's unlikely you'll be able to recycle your JavaScript on the server side. On the other hand, if you construct a lightweight, fast php validation tool you can use server-side validation via XHR instead of (a lot of the) JavaScript, and save yourself some redundancy the other direction.

However, that way's bound to be slower, so the best combination of user experience and security will probably come from having some redundancy in your validation.

Upvotes: 2

Ethan
Ethan

Reputation: 2784

This might be what you are looking for. It is not a javascript implementation. But this should provide all of your basic validation methods. I do not believe you would be able to find anything close to javascript unless you are using Node.js

Validator.php

Upvotes: 1

Related Questions