首页 > PHP开发 > form表单提交中文本框属性disabled与readOnly区别
2015
06-16

form表单提交中文本框属性disabled与readOnly区别

表单提交

今天碰到一个问题,当把一个input控件设置成disabled,发现form提交并把此值提交到后台,导致后台逻辑出现“未将对象引用设置到实例”的错,当把disabled改成readOnly后发现一切OK了,从中,我们也就知道disabeled与readOnly的一个区别了。

今天无意中看了一下W3C文档,看了一下form提交的postget方法的区别,还是先看原文吧:

17.13.1 Form submission method
The method attribute of the FORM element specifies the HTTP method used to send the form to the processing agent. This attribute may take two values:

get: With the HTTP "get" method, the form data set is appended to the URI specified by the action attribute (with a question-mark ("?") as separator) and this new URI is sent to the processing agent.
post: With the HTTP "post" method, the form data set is included in the body of the form and sent to the processing agent.
The "get" method should be used when the form is idempotent (i.e., causes no side-effects). Many database searches have no visible side-effects and make ideal applications for the "get" method.

If the service associated with the processing of a form causes side effects (for example, if the form modifies a database or subscription to a service), the "post" method should be used.

Note. The "get" method restricts form data set values to ASCII characters. Only the "post" method (with enctype="multipart/form-data") is specified to cover the entire [ISO10646] character set.

大致意思是:form提交的默认方式是“get”,get与set的区别:用get方式提交form表单时,会将参数跟在url后提交到后台处理,就是我们常见的?参数名=参数值的形式。并且会用ACSII码来编码参数以及参数值。post方式提交form表单时,不是在url后拖带参数,而是将数据内容带在form表单里一起提交到后台处理,这样数据不会被加密(只有当form的enctype="multipart/form-data"时,post提交才会用ISO10646来加密内容)。

上面几句话在我们的实际运用中有什么作用呢?那就是在诸多场景中的中文乱码的问题!当我们忘了给form表单设置form的method时(默认是get),会莫名其妙的出现一些中文乱码的问题,包括后台获取参数值时。

编程技巧