且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

***表格验证

更新时间:2023-02-26 19:02:00

如果我必须进行表单验证我通常运行一个客户端侧验证(JS),以便用户可以更正条目和服务器端验证,以检查是否所有字段都填写正确。


我也遵循现在的相同的事情。 .i正在考虑使用Ajax ...但是我得到了答案

它使用了大量的服务器资源..


@pradeepjain


你不需要ajax进行验证。如果你有一个很长的表单,我会帮助用户和JavaScript一起尽可能多地获取表单。那时我会用带宽来验证。如果我的代码是正确的并且它是合法用户,我不应该得到任何失败的验证服务器端,那些将要破解它的人将得到我的服务器端错误消息。


如果你有一个简短的论坛而且不介意提交表格进行验证的流量/资源,我会这样做。为什么麦芽汁两次。


在客户端进行此操作的第二个原因是可用性。将电话号码格式化并计算以确保我没有错过任何数字真是太好了。有些表格在每个字段旁边放置一个绿色复选标记,如果正确则填写,并且在我离开该字段后为那些不正确的字段添加红色X.


Dan


Hii guys,
My site has whole lots of forms...i wanted to know which is the best method for form validation.

say using ajax or javascript and server side or any other..if there is any example it would be better

If I have to do form validation I usually run a client side validation (JS) so that the user may correct the entries and a server side validation to check if really all fields were filled correctly.


I am also following the same thing as of now..i was thinking of Ajax ...but i got answers that
it uses lots of server resourse ..


@pradeepjain
You don''t need ajax for validation. If you''ve got a long form, I would assist the user along with JavaScript to get as much of the form right as possible. At that point I would use the bandwidth to validate. If my code is right and it''s a legitimate user, I shouldn''t get any failed validations server side, those people who are going to hack it, will get my server-side error message.

If you''ve got a short forum and don''t mind the traffic/resource of submitting the form for validation, I would just do it that way. Why do the wort twice.

Second reason to do it on client-side too is for usability. It''s so nice to have a phone number formatted and counted to make sure I didn''t miss a digit. Some forms put a green check mark next to each field I fill out if its correct and a red X for those that are incorrect after I''ve left that field.


Dan