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 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>
@ 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>
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.
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.
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.
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
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.
North America
Europe, Middle East and Africa
Asia Pacific