• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfinput validation not working - how do I debug?

New Here ,
Feb 11, 2010 Feb 11, 2010

Copy link to clipboard

Copied

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.

TOPICS
Getting started

Views

7.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 11, 2010 Feb 11, 2010

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 11, 2010 Feb 11, 2010

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 12, 2010 Feb 12, 2010

Copy link to clipboard

Copied

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

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2010 Feb 13, 2010

Copy link to clipboard

Copied

@ 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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 24, 2010 Apr 24, 2010

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 19, 2010 Nov 19, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 07, 2011 Nov 07, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 07, 2011 Nov 07, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 08, 2011 Nov 08, 2011

Copy link to clipboard

Copied

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....  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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 08, 2011 Nov 08, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 15, 2011 Nov 15, 2011

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation