Skip navigation
Olivia Crazy Horse
Currently Being Moderated

cfinput validation not working - how do I debug?

Feb 11, 2010 9:25 AM

I just need to make the field required, so I have this :

 

<cfinput type="text" name="tracking_number" required="yes" message="Carrier Tracking Number is required.">

 

 

However, when I just click submit, the form submits and the validation does not work. What is wrong with my code ?

 

I also have some javasript validation, so on cfform, I have this :

 

<cfform action="closeItem.cfm" method="post" name="closeItemForm" onSubmit="return ValidateForm()">

 

But I don't think the onSubmit will override the cfinput validation, will it ?

 

Seems simple enough, but I just cannot see what the problem is.

 
Replies
  • Currently Being Moderated
    Feb 11, 2010 10:26 AM   in reply to Olivia Crazy Horse

    This is from a form that works.

     

     

    <cfform action="inpatclinic/newrecordprocess.cfm" method="post" name="theform"
    onsubmit="return checkform(this);">

    <cfoutput>
    <cfinput type="text" name="date1"
    required="yes" message="Please Enter a Date"
    size="10" validate="date"  value="#yesterday#"></cfoutput>

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 11, 2010 8:11 PM   in reply to Olivia Crazy Horse

    Plz verify if your javascript option is enabled in the browser. U can try the below code too,

    <cfform

     

     

    method="post" action="">

     

     

    <cfinput type="text" name="tracking_number" required="yes" message="Carrier Tracking Number is required.">

     

    <cfinput type="submit" value="ok" name="Ok">

    </cfform>

     

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 12, 2010 10:25 PM   in reply to Olivia Crazy Horse

    Can you post a small / simple / self-contained code sample that demostrates this?

     

    --

    Adam

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 13, 2010 5:45 AM   in reply to Olivia Crazy Horse

    @ Olivia Crazy Horse

     

    I just need to make the field required, so I have this :

     

    <cfinput type="text" name="tracking_number" required="yes" message="Carrier Tracking Number is required.">

     

     

    However, when I just click submit, the form submits and the validation does not work. What is wrong with my code ?

     

    I also have some javasript validation, so on cfform, I have this :

     

    <cfform action="closeItem.cfm" method="post" name="closeItemForm" onSubmit="return ValidateForm()">

     

    But I don't think the onSubmit will override the cfinput validation, will it ?

     

    Seems simple enough, but I just cannot see what the problem is.

    Run the following basic test page.

     

    <cfif isdefined("form.sbmt")>
    <cfdump var="#form#">
    </cfif>

     

    <script type="text/javascript">
    function ValidateForm(){
         alert('ValidateForm() script called.');
         return true;
    }
    </script>


    <cfform method="post" name="closeItemForm" onSubmit="return ValidateForm()">    
    <cfinput type="text" name="tracking_number" required="yes" message="Carrier Tracking Number is required.">
    <cfinput name="sbmt" type="submit" value="send">
    </cfform>

     

    When you attempt to submit an empty field, it should show you the validation message.

    If not, view the page source in the browser. Are the following 2 lines (or similar) present in the source:

     

    <script type="text/javascript" src="/CFIDE/scripts/cfform.js"></script>
    <script type="text/javascript" src="/CFIDE/scripts/masks.js"></script>
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 19, 2010 9:56 AM   in reply to Olivia Crazy Horse

    Change the type property to flash. That will throw errors to help diagnose.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2011 6:27 AM   in reply to Olivia Crazy Horse

    We just found an interesting bug here.

     

    In a form where we used "fm-" as part of the form name, for example, <cfinput name="fm-email" required="yes" message="... the required validation failed.  We checked any attached javascrip and css to see if this was the root of the issue (by turning it off) and the required flags were still ignored.  When we removed the "fm-" from the form name, boom goes the dynamite, it worked.

     

    We then built a couple stand alone websites with a form where fm- was part of the cfinput name and they all failed.  As soon as we removed it, it worked.

     

    Aren't sure if its the hyphen or the fm that's making it break, but you all are free to research this further.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2011 12:16 PM   in reply to SharedDynamics

    It's the hyphen and it's not a bug.  This url, http://www.adobe.com/devnet-archive/server_archive/articles/using_cf_v ariables.html, will tell you what characters you may use in variable names.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 8, 2011 1:00 AM   in reply to Dan Bracuk

    That's (*) not relevant here, Dan, as your link discusses ColdFusion variables, whereas this validation is happening on the client.  There is nothing invalid about having a form control name with a hyphen in it, provided it's referenced correctly in any code using it.

     

    That said, I do not have the problem that "SharedDynamics" claims to have, so I don't think they've analysed the situation correctly/completely.

     

    This code works as expected for me:

     

    <cfform method="post" name="frm1">

        <cfinput type="text" name="fm-email" required="true" value="" />

        <cfinput type="submit" name="btnSubmit" value="Submit" />

    </cfform>

     

    --
    Adam

     

     

     

    (*) That link is also horribly old to be quoting.  A more contemporary version (which, admittedly, states the same thing, and is equally wrong) would be http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859 461172e0811cbec22c24-7fd3.html#WSc3ff6d0ea77859461172e0811cbec09af4-7f de.  There is no longer any such restriction on CF variable naming.  The restriction is only only on referencing variables using dot notation.  If one uses associative array notation, then one can call a variable whatever one likes, with - as far as I can tell - no restriction whatsoever.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 8, 2011 8:05 AM   in reply to Adam Cameron.

    provided it's referenced correctly in any code using it.

     

    If it is an older version of CF .. it probably does not handle dashes correctly.  Early versions often used dot notation in the javascript validation. So it is entirely possible the validation  works in later versions of CF, but not earlier ones.

     

     

    -Leigh

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 15, 2011 9:07 AM   in reply to -==cfSearching==-

    The "_number" field naming convention raised a flag for me - that looks suspiciously like a field that would get picked up by CF's built in server-side validation.  Could CF be ignoring the field validation on the client side because of the field suffix?  It might now affect everyone currently looking at the code on the forums because some of the more experienced CF devs might have turned that functionality off on their machines.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points