开发者

validation with both Javascript and PHP

开发者 https://www.devze.com 2023-04-10 18:39 出处:网络
Is there a g开发者_JS百科ood technique to ensure that the validation performed by PHP is identical to that performed my Javascript?There used to be a time where we would validate using javascript only

Is there a g开发者_JS百科ood technique to ensure that the validation performed by PHP is identical to that performed my Javascript?


There used to be a time where we would validate using javascript only and then people saw that you could bypass javascript validation so they started validating with PHP/ASP too. And then, people got bored, but sudenly, AJAX apperead :)

My recommendation that i use about 50% of the time is the following:

Just POST your form via ajax using your library of choice (i use jQuery) to a validation script made in php, expect a JSON return giving your errors or return some HTML to display to your user with the error. Using this technique, it looks like javascript validation because the page doesn't change and the validation is done on PHP side only.

Thats what i tend to implement when i can unless i'm forced to use file uploads (You can't use file uploads correctly with ajax posting) or unless my boss wants me to absolutely do real Javascript validation.

0

精彩评论

暂无评论...
验证码 换一张
取 消