admin管理员组文章数量:1292834
Is it better to validate PHP forms using php and then redirecting with errors, or is it better to use javascript validation and then just allow form submission if javascript is enabled.
Is it better to validate PHP forms using php and then redirecting with errors, or is it better to use javascript validation and then just allow form submission if javascript is enabled.
Share Improve this question asked Apr 5, 2011 at 14:19 VishVish 4,49210 gold badges45 silver badges76 bronze badges5 Answers
Reset to default 11You must validate values on the server side, since the client cannot be trusted.
You may validate values on the client side to provide better UX for those with JavaScript enabled.
I usually do both. If you can check the fields in javascript, it saves them the loading time and spares your server the hit. You still have to check again on the server in case they had javascript disabled, or intentionally bypassed it.
use javascript to validate format, e.g. email format, password length, etc.
use php to validate db if same record exists, e.g. same username
except hackers, 99% ppl enable javascript, so just throw this worry away.
here I remend jquery validation plugin for client side validation.
Is better making both together because php can handle raw request without using or enabling javascript, javascript, can speed-up the check process and handle it in an elegant graphic way
Definitely both. Users can turn off Javascript or even edit your validation script since it is local (using Firebug or some other such tool). Yes, this means that you will likely write the same validation script in two separate languages at approximately the same time, but that's an essential way to avoid incorrect or malformed data from being submitted.
本文标签: javascriptHow to validate Forms in PHPStack Overflow
版权声明:本文标题:javascript - How to validate Forms in PHP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741561923a2385497.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论