Coldfusion中的表单验证

时间:2013-12-11 12:12:27

标签: javascript forms validation coldfusion

我正在尝试验证我的表单,因此它不接受空字段。 您可以看到我尝试使用“必需”属性对“国家/地区”进行验证,但这不起作用....

我只想在某些字段上进行验证:Country,Address,City和ReceptionNumber

以下是表单的代码:

<head>

    <title>Office Location Entry Form</title>
    <LINK rel="stylesheet" type="text/css" href="css/style.css">
    <cfinclude template="CheckUserLogin.cfm">

</HEAD>


<body background="FFFFFF" bgcolor="#FFFFFF">

    <P class="paratitle"><br> Country Offices Entry Form <BR>
    <P class="normal">Please fill in as many fields as possible. Please include the country dial code when entering phone or fax numbers.</p>

<!--- Entry form --->
<FORM name="officeLocations" action="officeLocations_EntryAction.cfm" method="post" onSubmit="return ValidateInput(this);">

    <TABLE>
        <!--- Field: office_locations.Country --->
        <TR>
        <TD valign="top" class="normal"> Country </TD>
        <TD valign="top" class="normal">

        <input type="text" name="Country" size="30" maxlength="510" class="input" required="yes" message="You must enter a first country."> 
    </TD>
    </TR>


    <!--- Field: office_locations.address --->
    <TR>
    <TD valign="top" class="normal"> Address</TD>
    <TD valign="top" class="normal">

        <INPUT type="text" name="address" size="30" value="" maxLength="510" class="input">

    </TD>
    </TR>

    <!--- Field: office_locations.address2 --->
    <TR>
    <TD valign="top" class="normal"> Address 2</TD>
    <TD valign="top" class="normal">

        <INPUT type="text" name="address2" size="30" value="" maxLength="510" class="input">

    </TD>
    </TR>

    <!--- Field: office_locations.address3--->
    <TR>
    <TD valign="top" class="normal"> Address 3</TD>
    <TD valign="top" class="normal">

        <INPUT type="text" name="address3" size="30" value="" maxLength="510" class="input">

    </TD>
    </TR>

    <!--- Field: office_locations.address5--->
    <TR>
    <TD valign="top" class="normal"> Address 4</TD>
    <TD valign="top" class="normal">

        <INPUT type="text" name="address4" size="30" value="" maxLength="510" class="input">

    </TD>
    </TR>

    <!--- Field: office_locations.address4 --->
    <TR>
    <TD valign="top" class="normal"> City</TD>
    <TD valign="top" class="normal">

        <INPUT type="text" name="city" size="30" value="" maxLength="510" class="input">

    </TD>
    </TR>

    <!--- Field: office_locations.postcode --->
    <TR>
    <TD valign="top" class="normal"> Postal code</TD>
    <TD valign="top" class="normal">

        <INPUT type="text" name="postcode" size="30" value="" maxLength="510" class="input">

    </TD>
    </TR>

    <!--- Field: office_locations.receptionnumber --->
    <TR>
    <TD valign="top" class="normal"> Reception number</TD>
    <TD valign="top" class="normal">

        <INPUT type="text" name="receptionnumber" size="30" value="" maxLength="510" class="input">

    </TD>
    </TR>

    <!--- Field: office_locations.mainnumber --->
    <TR>
    <TD valign="top" class="normal"> Main number</TD>
    <TD valign="top" class="normal">

        <INPUT type="text" name="mainnumber" size="30" value="" maxLength="510" class="input">

    </TD>
    </TR>

    <!--- Field: office_locations.faxnumber --->
    <TR>
    <TD valign="top" class="normal"> Fax number</TD>
    <TD valign="top" class="normal">

        <INPUT type="text" name="faxnumber" size="30" value="" maxLength="510" class="input">

    </TD>
    </TR>


    <INPUT type="hidden" name="timestamp" value="<CFOUTPUT>#DateFormat(Now())#, #TimeFormat(Now())#</CFOUTPUT>" size="">
    <INPUT type="hidden" name="username" value="<CFOUTPUT>#Session.FirstName# #Session.LastName#</CFOUTPUT>" size="">
    <INPUT type="hidden" name="NTusername" value="<cfoutput>#Session.NtUserName#</cfoutput>" size="">
</TABLE>
<P>
<input type="image" src="IMAGES/AddItButton.gif" align="absmiddle">

</FORM>

</body>



</html></HTML>

由于

1 个答案:

答案 0 :(得分:1)

根据要求我发布这个作为答案,但我不能强调这种方法非常糟糕。但是,它确实回答了你的问题。

来自问题的评论:

  

您的意思是<input>代码为<cfinput>,并且这是一个   <cfform>?据我所知,HTML 5有一个必需的属性   ,但没有消息。 HTML 4也没有。但两者都是   <cfinput>的属性..?        哦,无论如何你不应该使用<cfform><cfinput>。使用Javascript正确完成工作(并匹配服务器端   验证)。