Skip to main content
Inspiring
October 23, 2008
Question

cfinput required not working

  • October 23, 2008
  • 3 replies
  • 611 views
I am using cfinput and want to make the field required, but it does not seem to be working. I can submit without any problems, but I should get an error message. The cfinput is in a loop and it dynamically generates inputs based on the loop.

Here is my code below :

<center>
<table border="0" width="760">
<tr>
<td class="TitleText">
<cfoutput query="qrySerialNumbers" group="materialNumber"><font face="Verdana" size="2"><b>Material Number:</b> #materialNumber#</font><p>
<cfloop from="1" to="#quantity#" index="i">
<table border="0" width="300">
<tr>
<td align="left" class="TitleText" width="140">
<b>Serial Number #i#:</b> </td>
<td align="left" width="160"><cfinput type="text" name="serialNumber" required="Yes" Message="Serial Number must be entered."><input type="hidden" name="gfmPartNumberID" value="#gfmPartNumberID#"><br></td>
</tr>
</table>
</cfloop>
<p>
<p>
</cfoutput>
</td>
</tr>
</table>
</center>
    This topic has been closed for replies.

    3 replies

    trojnfnAuthor
    Inspiring
    October 25, 2008
    I am told that my cfinput validation will not work because the cfinputs are dynamically generated and they all have the same name.

    My code is below :

    <center>
    <table border="0" width="760">
    <tr>
    <td class="TitleText">
    <cfoutput query="qrySerialNumbers" group="materialNumber"><font face="Verdana" size="2"><b>Material Number:</b> #materialNumber#</font><p>
    <cfloop from="1" to="#quantity#" index="i">
    <table border="0" width="300">
    <tr>
    <td align="left" class="TitleText" width="140">
    <b>Serial Number #i#:</b> </td>
    <td align="left" width="160"><cfinput type="text" name="serialNumber" required="Yes" Message="Serial Number must be entered."><input type="hidden" name="gfmPartNumberID" value="#gfmPartNumberID#"><br></td>
    </tr>
    </table>
    </cfloop>
    <p>
    <p>
    </cfoutput>
    </td>
    </tr>
    </table>
    </center>

    If I change the serialNumber to serialNumber#i#, the cfinput validation does work, since they all have different names now.

    However, what do I need to change n my update code to accomodate #i# ? Here is my udpdate code :

    <cftransaction>
    <cfloop from="1" to="#listlen(form.serialNumber)#" index="i">
    <cfquery name="qrySerialNumberID" datasource="recDisc">
    select max(SerialNumberID) as maxSerialNumberID
    from gfmSerialNumbers
    </cfquery>
    <!--- Get the next transaction id by adding 1 to the last number --->
    <cfset nextSerialNumberID = #qrySerialNumberID.maxSerialNumberID# + 1>


    <cfset col2 = listgetat(form.gfmPartNumberID, i)>
    <cfset col3 = listgetat(form.serialNumber, i)>

    <cfquery name="qryInsertSerial" datasource="recDisc">
    insert into gfmSerialNumbers
    (serialNumberID,
    gfmPartNumberID,
    serialNumber,
    status)

    values
    ('#nextSerialNumberID#',
    '#col2#',
    '#ucase(col3)#',
    '1')

    </cfquery>
    </cfloop>
    </cftransaction>

    The above code works without the #i#, it will just not validate. To validate, I need to use #i#, but now the insert will not work. What do I need to do ?

    Thanks for any help.
    Inspiring
    October 24, 2008
    All your cfinput tags have the same name. As long as one of them is filled in, there will be a value for that form field.

    trojnfnAuthor
    Inspiring
    October 24, 2008
    If I submit the form without inputting anything, the form submits. I should at least get one error message, for the first input ?
    Inspiring
    October 24, 2008
    is this inside a <cfform> ?

    Maybe the problem is with the looped dynamic inputs all having the same
    name.




    Michael Evangelista, Evangelista Design
    Web : www.mredesign.com Blog : www.miuaiga.com
    Developer Newsgroups: news://forums.mredesign.com
    trojnfnAuthor
    Inspiring
    October 24, 2008
    Yes, it is inside a cfform.

    If they all have the same name, shouldn't the first one at least validate ? I am able to submit the form without inputting anything.