Copy link to clipboard
Copied
Can coldfusion validate a form who's checkbox must be ticked ?
ie if the checkbox isn't ticked (terms and conditions) bring up a coldfusion dialogue box saying "checkbox must be ticked before proceeding" ?
Copy link to clipboard
Copied
There is no such thing as a "ColdFusion Dialogue".
Dialouges are the relm of the client. You would need client logic to invoke on. JavaScript is that common scripting language of the client.
ColdFusion has some wizards and special tags that will create some canned JavaScript for you. One of these is a required property on a <cfinput...> tag. IIRC this might work with check box controls, but I am not sure.
Either way, you need to write code to handle the form field not being submitted. Whether you write the JavaScript, ColdFusion provides canned JS or you apply some other JS library, if the user has turned off JavaScript that code is not going to run. That means that if the control is not selected, the form field will not be provided by the browser to the server when the form is submitted.
You should provide server side logic that checks the existance of that field, and display appropiate resonses if it does not exist.
Copy link to clipboard
Copied
I was just using the CFFORM built in validation and wanted a quick way to check if the checkbox had been ticked. when the user hit submit - its for terms and conditions
Copy link to clipboard
Copied
One of these is a required property on a <cfinput...> tag. IIRC this might work with check box controls, but I am not sure.
I was rather surprised just now to discover that it doesn't.
I've just been raising this with Adobe... and in the mean time you beat me to the punch responding here. you said pretty much what I was gonna say.
To the OP... you should do some reading:
CFFORM
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fb7.html
CFINPUT
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f51.html
(plus at least superficial reading of the other form-oriented tags)
Requesting and Presenting Information
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cdd70508c-8000.html (all of it).
--
Adam
Copy link to clipboard
Copied
You can bring up a javaScript prompt using required="yes" like this:
<cfinput type="checkbox" name="myCheckbox" message="Please check the box." required="yes" id="myCheckbox" value="checkbox">
But you should also use some sort of server-side validation when the form is submitted for folks that have JavaScript disabled.
<cfif NOT isDefined("FORM.myCheckbox")>
ERROR RESPONSE HERE
</cfif>
Ken Ford
Copy link to clipboard
Copied
You can bring up a javaScript prompt using required="yes" like this:
<cfinput type="checkbox" name="myCheckbox" message="Please check the box." required="yes" id="myCheckbox" value="checkbox">
Are you sure about that? Dun't work for me on CF 8.0.1.
--
Adam
Copy link to clipboard
Copied
Hmmm, works on CF 9:
http://www.fordwebs.com/examples/checkbox.cfm
But not CF 8:
http://www.markdunning.com/checkbox.cfm
Ken Ford
Copy link to clipboard
Copied
Hmmm, works on CF 9:
http://www.fordwebs.com/examples/checkbox.cfm
But not CF 8:
Good to know. Cheers mate.
--
Adam
Copy link to clipboard
Copied
It works for me with 8.0.1. Are you sure your CFIDE mapping is working?
EDIT: I know I have tweaked my fform.js file. So I went to compare it with yours but got a 404 error for - http://www.markdunning.com/CFIDE/scripts/cfform.js .
Message was edited by: -==cfSearching==-
Copy link to clipboard
Copied
The CFIDE doesn't appear to be mapped correctly on that one, but is on this one:
http://www.nmacademy.net/checkbox.cfm
So it works on CF 8.01 also.
Ken Ford
Copy link to clipboard
Copied
It works for me with 8.0.1. Are you sure your CFIDE mapping is working?
I am sure that it is. Now 😉
Yeah, for some reason this machine (relatively new to me) didn't have it set up.
Good catch. I feel thick.
--
Adam
Copy link to clipboard
Copied
> ... this machine (relatively new to me) didn't have it set up
Yeah, I hate getting used to new machines. There is always something I forget to configure and have to spend 20 minutes figuring out what it is ...
Copy link to clipboard
Copied
> ... this machine (relatively new to me) didn't have it set up
Yeah, I hate getting used to new machines. There is always something I forget to configure and have to spend 20 minutes figuring out what it is ...
Heh. Well "in my defence" this one was set up by our IT dept.
But it's actually by design. We specifically do not use anything in the CFIDE dir on the live environment, and this is a replication of the live environment.
This does not make me any less stupid, as I already know all this, and when CFFORM stuff seems not to work, the first assumption should always be "check the CFIDE mapping". I know this. Supposedly.
Sigh.
--
Adam
Copy link to clipboard
Copied
You might not need server side validation. The normal way of doing terms and conditions is to not enable the submit button unless the box is checked.
Copy link to clipboard
Copied
Ok, I've set checkbox to reqd and its value to "N" message="please tick box etc.."
and that works
when box is unticked, I get dialogue box
when ticked, the form proceeds
Copy link to clipboard
Copied
And you have tested it with JavaScript turned off, and get desired behavior?
Copy link to clipboard
Copied
um... use required="yes" and a message="you gots ta click the box"