Copy link to clipboard
Copied
I am Using a cfform and cfinput tags for form validation and I am wondering if It is possible to use jQuery to take an action based on the validation results.
More specifically, I want to disable the submit button when it is clicked so that the user doesnt click it more than once but if there are errors on the form, I would liek to re-enable the submit button.
Is it possible to do this using the built in CF8 form validation or do i have to use somethign liek the jquery validate plugin to accomplish this?
I know that I can use either jquery or coldfusion for form validation but what I was trying to figure out is if I use coldfusion for client side form validation, do those coldfusion functions return a value that I can acres which indicates if te coldfusion validation found any errors?
If you're comfortable with JQuery, I recommend not even attempting to use CF's client-side form validation. It's kinda intended for people who aren't comfortable with clientside scripting, but still need [something
...Copy link to clipboard
Copied
It's possible with javascript and jquery is javascript so it must be possible with jquery.
The way we implement this concept is with a javascript script called PleaseWait(theform). We call it like this:
<cfform name="theForm" action="#somepage.cfm" method="POST" onsubmit="return pleasewait(this)">
Copy link to clipboard
Copied
hey thanks for the reply!
I'm not sure I follow though... I knwo that I can call a javasctipt function on form submit - but how can I tell whether there were errors that came back from the cfform client side validation?
Copy link to clipboard
Copied
bdee2 wrote:
hey thanks for the reply!
I'm not sure I follow though... I knwo that I can call a javasctipt function on form submit - but how can I tell whether there were errors that came back from the cfform client side validation?
Isn't it the task of the Javascript function to tell whether there were errors? You may use JQuery's validation script (of which there's plenty of documentation on the web), or the built-in validation in cfform. It all comes down to your needs.
JQuery validation is more elaborate and comes mostly ready-made. You'll usually have to tinker with it, if it doesn't fit your situation. You have to weigh that against cfform's lighter, mostly hands-off scripts. You may not tamper with them, as they are system scripts.
Copy link to clipboard
Copied
I know that I can use either jquery or coldfusion for form validation but what I was trying to figure out is if I use coldfusion for client side form validation, do those coldfusion functions return a value that I can acres which indicates if te coldfusion validation found any errors?
Copy link to clipboard
Copied
Whatever you use on the client for validation will not return anything to the server unless you write something to make that happen. The usual way that client side validation works is that if the user doesn't enter what he's supposed to, the form won't submit.
Copy link to clipboard
Copied
bdee2 wrote:
I know that I can use either jquery or coldfusion for form validation but what I was trying to figure out is if I use coldfusion for client side form validation, do those coldfusion functions return a value that I can acres which indicates if te coldfusion validation found any errors?
We probably didn't understand each other well. In ColdFusion, the in-built client-side validation occurs behind the scenes. These are pre-programmed Javascript set pieces to validate for empty fields, field-length and for common types like zipcode, e-mail, telephone number and so on.
In standard usage, ColdFusion doesn't return a value to you, the developer. The return value is contained implicitly in the error message. Here is an example that validates input for e-mail. If you attempt to submit the form with an invalid e-mail address, ColdFusion will automatically generate an error message.
<cfform>
<cfinput name="emailAddress" type="text" required="true" validate="email">
<cfinput name="sbmt" type="submit" value="send">
</cfform>
If you wish to customize the validation, then you will have to do your own. The following example validates the username according to my needs
<!--- My custom validation for username --->
<script language="JavaScript" type="text/javascript">
<!--
var isNameValid = false;
var regex = /[a-zA-Z0-9]{8,16}/;
function check_username(form, ctrl, value) {
if (value.match(regex) == value) {
isNameValid = true;
}
return isNameValid;
}
//-->
</script>
</head>
<cfform name="myForm" id="myForm">
<cfinput name="username" type="text" onValidate="check_username" message="A username must be alphanumeric and must have between 8 and 16 characters.">
<cfinput name="sbmt" type="submit" value="send">
</cfform>
Copy link to clipboard
Copied
I know that I can use either jquery or coldfusion for form validation but what I was trying to figure out is if I use coldfusion for client side form validation, do those coldfusion functions return a value that I can acres which indicates if te coldfusion validation found any errors?
If you're comfortable with JQuery, I recommend not even attempting to use CF's client-side form validation. It's kinda intended for people who aren't comfortable with clientside scripting, but still need [something] on the clientside.
<cfform>'s validation is to client-side validation what <cfinsert> is to an SQL INSERT statement: designed for those who can't do it themselves. As such they're very simplistic, and also rather "blackbox" as they're not intended to be part of a comprehensive solution.
Best avoided if one can DIY.
--
Adam
Copy link to clipboard
Copied
Regarding, "
<cfform>'s validation is to client-side validation what <cfinsert> is to an SQL INSERT statement: designed for those who can't do it themselves. As such they're very simplistic, and also rather "blackbox" as they're not intended to be part of a comprehensive solution.
Best avoided if one can DIY."
I disagree. Both those tags do simple things well. If their functionality satisfies your requirements then doing it yourself is a case of reinventing the wheel.
Copy link to clipboard
Copied
thanks for the clarification - I think i will just use jQuery for my validation.