简体   繁体   English

HTML表单值PHP和空格

[英]HTML Form Values PHP and Spaces

I am working on various projects for my organization that were started by another developer. 我正在为我的组织开展由其他开发人员启动的各种项目。 A good portion of this work involves form processing with PHP. 这项工作的很大一部分涉及使用PHP进行表单处理。

I was rather surprised to see that for many of the form values, the previous developer used spaces (for example <input type="radio" value="DO NOT ENROLL" name="proceed" /> ) . 我很惊讶地看到,对于许多表单值,前一个开发人员使用空格(例如<input type="radio" value="DO NOT ENROLL" name="proceed" /> ) I think I know why he did it - he sends it as it email and makes it easy to display the values in a human readable format without additional processing, but, as someone who is used to 'typical' programming naming conventions (no spaces, camel case, pascal case, and so on), this does make me a little uneasy. 我想我知道他为什么这么做了 - 他发送电子邮件,并且可以很容易地以人类可读的格式显示值而无需额外的处理,但是,作为习惯于'典型'编程命名约定的人(没有空格,骆驼案,帕斯卡案等等,这确实让我有点不安。 Whenever I have processed HTML forms and assigned values, I believe I always tried to following "typical" variable naming conventions, but this could have habit rather than a necessary practice. 每当我处理HTML表单和赋值时,我相信我总是试图遵循“典型”变量命名约定,但这可能有习惯而不是必要的练习。

Now, I am not saying he is wrong, but I tried to do a little research on the topic and have not reached a definite conclusion. 现在,我并不是说他错了,但我试着对这个话题进行一些研究,并没有得出明确的结论。 So my question is this - is there anything wrong with including spaces in values assigned to HTML form input elements - particularly when it will be sent over email? 所以我的问题是 - 在分配给HTML表单输入元素的值中包含空格是否有任何问题 - 特别是当它将通过电子邮件发送时? If so, what complications may result, and is there a way to properly process them, or would you recommend keeping the actual form values simple (for example, <input type="radio" value="decline" name="proceed" /> and THEN processing them to make them more readable after the form is submitted. 如果是这样,可能会导致哪些复杂情况,并且有没有办法正确处理它们,或者您是否建议保持实际表单值简单(例如, <input type="radio" value="decline" name="proceed" />然后处理它们以使表单提交后更具可读性。

Thanks for any input! 感谢您的任何意见!

There is nothing bad, except the only real restriction on what characters can appear in form control names is when a form is submitted with GET 没有什么不好的,除了对表单控件名称中出现的字符的唯一真正限制是使用GET提交表单时

"The "get" method restricts form data set values to ASCII characters. “”get“方法将表单数据集值限制为ASCII字符。

Source 1 | 来源1 | Source 2 来源2

I would definitely change them to camel case, pascal case or whatever else closer to coding conventions/standards. 我肯定会将它们改为骆驼案,pascal案或其他更接近编码惯例/标准的案例。 It may work either way, but...better be safe than sorry. 它可以以任何一种方式工作,但是...更安全而不是抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM