Coldfusion CFSELECT Validation Fails

Most of us have issues with Coldfusion CFSELECT Validation i.e. form submits even though he didnt select an entry from drop down list and you have validation in CFSELECT . Here is the solution to this issue.

1. The validation works only if you have size attribute of cfselect set to a value greater than 1.

Here is my code that works

<cfselect name="sec_question" required="yes" message="You must select a security question to reset your password." size="2">

<option value="1">What is your mother's maiden name?
<option value="2">In what city were you born?
<option value="3">What is the title of your favorite book?
<option value="4">What is your favorite pet's name?

</cfselect>

2. Here are some observations

a. I didnt require selected="" attribute inside cfselect

b. I didnt require Please select a value i.e. with a space or without space(either way, I tried and it didnt work)

So try this and I am sure you wont be dissapointed. It took me a while to figure it out and I tried different options before I succeeded.

My post can also be found at Adobe CF docs

http://livedocs.adobe.com/coldfusion/7/htmldocs/00000331.htm
or
http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000331.htm

Let me know if it doesnt work or if you have a question.

Comments

Furqan Ahmed said…
Hi,

I have tried your way. It does start validating it. :)

However it converts my drop down box to list box. :(

Can you please help me with that.

---------------------------
This is my drop down code:

cfselect name="role" required="yes" message="Please choose a role type" size="3"

option value=""/option
option value="admin"Admin/option
option value="user"User/option

/cfselect

< bracket has been intentionally removed due to limitation of comment box
---------------------------

Many Thanks
Ajas Mohammed said…
Please post a snapshot if possible.

Popular posts from this blog

Making text bold in Adobe Acrobat

Java Keytool Export Private Key, PKCS#12 or .p12 export or conversion from java keystore