CFML注册表遇到麻烦 - 正确使用encodeForHTMLAttribute?

时间:2018-01-05 19:02:14

标签: forms coldfusion cfml lucee

Lucee 5.2

MS SQL Server 2014

嗨,朋友们,

我需要一些CFML任务的帮助 - 这是一个客户的会议注册表。

在下面的代码中,我正确使用encodeForHTMLAttribute吗?我一直在对encodeForHTMLAttribute进行一些研究 - 例如,https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-e-g/encodeforhtmlattribute.html - 但我不确定a)我是否正确使用它,或者b)如果我甚至需要使用它。

下面的CFML看起来合理吗?一如既往地感谢您的帮助。

埃里克

<!--- begin CFOUTPUT for user input fields --->
<cfoutput>
<li>
<label for="Title"><h3>Title (Ms., Mr., Dr. etc.):</h3></label>
<input type="text" name="Title" placeholder="Title" value="#encodeForHTMLAttribute(Trim(Left(form.Title,255)))#" maxlength="255" tabindex="1" size="70" autofocus="true" />
</li>

<li>
<label for="x_first_name"><h3>First Name:</h3></label>
<input type="text" name="x_first_name" placeholder="First Name" value="#encodeForHTMLAttribute(Trim(Left(form.x_first_name,255)))#" maxlength="255" tabindex="2" size="70" required="yes" />
        <span class="form_hint">Enter First Name</span>
</li>

<li>
<label for="MiddleInitial"><h3>Middle Initial:</h3></label>
<input type="text" name="MiddleInitial" placeholder="MI" value="#encodeForHTMLAttribute(Trim(Left(form.MiddleInitial,255)))#" maxlength="5" tabindex="3" size="1" />
</li>

<li>
<label for="x_last_name"><h3>Last Name:</h3></label>
<input type="text" name="x_last_name" placeholder="Last Name" value="#encodeForHTMLAttribute(Trim(Left(form.x_last_name,255)))#" maxlength="255" tabindex="4" size="70" required="yes" />
        <span class="form_hint">Enter Last Name</span> 
</li>

<li>
  <label for="Credentials"><h3>Credentials:</h3></label>
<input type="text" name="Credentials" placeholder="Credentials (e.g. RN, MSN, PhD, MD)" value="#encodeForHTMLAttribute(Trim(Left(form.Credentials,255)))#" maxlength="255" tabindex="5" size="70" required="yes" />
     <span class="form_hint">Credentials (e.g. RN, MSN, PhD, MD)</span> 
</li>

<li>
<label for="x_company"><h3>Current Position and Organization:</h3></label>
<input type="text" name="x_company" placeholder="Current Position and Organization" value="#encodeForHTMLAttribute(Trim(Left(form.x_company,255)))#" maxlength="255" tabindex="6" size="70" required="yes" />
        <span class="form_hint">Enter Current Position and Organization</span>               
</li>

<li>
<label for="x_address"><h3>Address:</h3></label>
<input type="text" name="x_address" placeholder="Please enter your address" value="#encodeForHTMLAttribute(Trim(Left(form.x_address,255)))#" maxlength="255" tabindex="7" size="70" required="yes" />
        <span class="form_hint">Please enter your mailing address</span> 
</li>

<li>
<label for="x_city"><h3>City:</h3></label>
<input type="text" name="x_city" placeholder="Please enter your city" value="#encodeForHTMLAttribute(Trim(Left(form.x_city,255)))#" maxlength="255" tabindex="8" size="70" required="yes" />
        <span class="form_hint">Please enter your city</span> 
</li>

<li>
  <label for="x_state"><h3>State or Province:</h3></label>
<input type="text" name="x_state" placeholder="Please enter your State or Province" value="#encodeForHTMLAttribute(Trim(Left(form.x_state,255)))#" maxlength="255" tabindex="9" size="70" required="yes" />
        <span class="form_hint">Please enter your State or Province</span>             
</li>                     


<li>
<label for="x_zip"><h3>ZIP or Postal Code:</h3></label>
<input type="text" name="x_zip" placeholder="Please enter your ZIP or Postal Code" value="#encodeForHTMLAttribute(Trim(Left(form.x_zip,25)))#" maxlength="255" tabindex="10" size="70" required="yes" />
        <span class="form_hint">Please enter your ZIP or Postal Code</span>               
</li> 

           <li>
<label for="x_country"><h3>Country:</h3></label>
<input type="text" name="x_country" placeholder="Please enter your country" value="#encodeForHTMLAttribute(Trim(Left(form.x_country,255)))#" maxlength="255" tabindex="11" size="70" required="yes" />
        <span class="form_hint">Please enter your country</span>                
</li>  

           <li>
<label for="TelephoneWork"><h3>Work Telephone:</h3></label>
<input type="text" name="TelephoneWork" placeholder="Please enter your work telephone number" value="#encodeForHTMLAttribute(Trim(Left(form.TelephoneWork,25)))#" maxlength="25" tabindex="13" size="70" />
        <span class="form_hint">Please enter your work telephone number.</span> 
</li>     

<li>
<label for="x_email"><h3>email address:</h3></label>
<input type="text" name="x_email" placeholder="Important: Please enter your valid email address." value="#encodeForHTMLAttribute(Trim(Left(form.x_email,128)))#" maxlength="128" tabindex="16" size="70" required="yes" />
        <span class="form_hint">Enter Email Address</span> 
</li>

<li>
<label for="SpecialRequirements"><h3>Special Requirements -- dietary, mobility, etc.:</h3></label>

<input type="text" name="SpecialRequirements" placeholder="Important: Please enter special requirements, if any." value="#encodeForHTMLAttribute(Trim(Left(form.SpecialRequirements,255)))#" 
maxlength="255" tabindex="18" size="70" />

</li>
</cfoutput><!--- /CFOUTPUT for user input fields --->

2 个答案:

答案 0 :(得分:5)

问题1

在表单字段中设置属性时使用。

encodeForHTMLAttribute()

问题2

美元的货币字段应为

type="number" step="0.01"

其他货币有不同的重要性

问题3

您必须添加描述响应页面的代码。没有足够的信息来确定问题。

答案 1 :(得分:0)

您的第一个问题是In the code below, am I using encodeForHTMLAttribute correctly?。答案是否定的,因为你在错误的地方使用它。

encodeForHTMLAttribute函数将某些字符更改为其html等效字符。例如,小于号码<变为&lt;。如果您在网页的显示标记中输出此内容(例如段落或表格详细信息),则会看到<。但是,在输入标记中,您会看到&lt;这是您希望用户看到的内容吗?

您的下一个问题是Does the CFML below look reasonable?。语法很好但是它包含一个从表单帖子中预先填充的html的事实让我觉得很奇怪。您是否让用户两次发布相同的信息?