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

<cfinput type="checkbox" - way to validate if checkbox IS ticked ?

Participant ,
Jun 07, 2010 Jun 07, 2010

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"  ?

TOPICS
Getting started
5.4K
Translate
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 ,
Jun 07, 2010 Jun 07, 2010

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.

Translate
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
Participant ,
Jun 07, 2010 Jun 07, 2010

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

Translate
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 ,
Jun 07, 2010 Jun 07, 2010
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

Translate
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
Participant ,
Jun 07, 2010 Jun 07, 2010

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

Translate
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 ,
Jun 07, 2010 Jun 07, 2010

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

Translate
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
Participant ,
Jun 07, 2010 Jun 07, 2010
Translate
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 ,
Jun 07, 2010 Jun 07, 2010

Hmmm, works on CF 9:

http://www.fordwebs.com/examples/checkbox.cfm

But not CF 8:

http://www.markdunning.com/checkbox.cfm

Good to know.  Cheers mate.

--

Adam

Translate
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 ,
Jun 07, 2010 Jun 07, 2010

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

Translate
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
Participant ,
Jun 07, 2010 Jun 07, 2010

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

Translate
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 ,
Jun 07, 2010 Jun 07, 2010

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

Translate
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 ,
Jun 07, 2010 Jun 07, 2010

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

Translate
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 ,
Jun 07, 2010 Jun 07, 2010

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

Translate
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 ,
Jun 07, 2010 Jun 07, 2010

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.

Translate
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
Participant ,
Jun 07, 2010 Jun 07, 2010

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

Translate
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 ,
Jun 07, 2010 Jun 07, 2010

And you have tested it with JavaScript turned off, and get desired behavior?

Translate
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 ,
Jan 12, 2011 Jan 12, 2011
LATEST

um... use required="yes" and a message="you gots ta click the box"

Translate
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