我对表单验证过程很新。如果提交表单,如果输入值为空字符串,如何返回值 null ?
从下面的示例中可以看出,我有三个用于验证用户身份的选项。根据所选的单选按钮,用户可以继续输入相关详细信息。提交表单后,我希望空字段(未选择其他2个选项)返回值“null”或“empty”而不是“,,,”。你能帮忙解决这个问题。
请参阅下面的代码示例:
<TR><TD colspan="2" align="left">
<TABLE width="100%" cellpadding="5" style="background-color:<%=colourblock%>; color:#FFFFFF; font-size:16px; display:block; margin-bottom:10px;"><TR><TD style="color:#FFFFFF;font-size:18px;">Step 10 - Provide identification</TD></TR></TABLE><BR /><strong>Please confirm your identity using one of the below Government issued identification.</strong><BR /><BR />
<TR><TD width="253"><input type="radio" name="IdentityType" id="IdentityType" value="**Australian driver's licence number**">
<label for="IdentityType">Australian driver's licence number:</label> </TD><TD width="672"><span id="sprytextfield1">
<input name="IdentityValue" type="text" id="IdentityValue" value="" /></span></TD></TR>
<TR><TD><input type="radio" name="IdentityType" id="IdentityType" value="**Australian passport number**"><label for="IdentityType">Australian passport number:</label></TD><TD>
<input name="IdentityValue" type="text" id="IdentityValue" value="" /></TD></TR>
<TR><TD><input type="radio" name="IdentityType" id="IdentityType" value="**Immicard number**"><label for="IdentityType">Immicard number: </label></TD><TD>
<input name="IdentityValue" type="text" id="IdentityValue" value="" /></TD></TR>
<TR><TD colspan="2" align="left"><BR >
If you don't hold any of these identification, you will need to attach certified copies of relevant proof of identity documents as outlined on the proof of identity guide on <a href="http://www.plum.com.au" target="_blank"><strong>plum.com.au</strong></a><BR /><BR />
</TD></TR>
答案 0 :(得分:0)
处理代码时,它将始终作为空字符串发布(使用经典的asp vbscript时)。如果您将值设置为null,则将其分配为null,如下所示:
dim IdentityValue : IdentityValue = Request.Form("IdentityValue")
if IdentityValue = "" then IdentityValue = null
现在IdentityValue将为null