Skip to main content
Known Participant
February 11, 2010
Question

cfinput validation not working - how do I debug?

  • February 11, 2010
  • 7 replies
  • 7292 views

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.

This topic has been closed for replies.

7 replies

Inspiring
November 7, 2011

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.

Inspiring
November 7, 2011

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

Inspiring
November 8, 2011

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/WSc3ff6d0ea77859461172e0811cbec22c24-7fd3.html#WSc3ff6d0ea77859461172e0811cbec09af4-7fde.  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.

Known Participant
November 19, 2010

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

BKBK
Community Expert
Community Expert
February 13, 2010

@ 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>
Inspiring
February 13, 2010

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

--

Adam

February 12, 2010

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>

Inspiring
February 11, 2010

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>