Friday, October 14, 2005

CFFORM validation does not work

Goal:
CFFORM validation does not work.

Story:
I have faced this issue quite a few times so far. There are many ColdFusion servers, in my company. We keep on upgrading hardware of servers very frequently. Every new installation of operating system requires the installation of ColdFusion.

Personally, I like to use the regular FORM over CFFORM and write my own JavaScript validation. Well, there is a lot of “ancient” code, which we are cleaning up as we go. After importing all the code, configuration and settings while try to use forms sometime CFFORM does not work. When I move the same code to different server to test code it works as expected and when we move it back it does not work. This was quite a surprising problem for a while. We have blamed browser, operating system, domain etc thing for this issue; none of them are correct.

Problem:
The error we faced was

Line:8 Error: Object Expected

None of the JavaScript Validation worked. Form did not preserve any of the data which was posted back.

Solution:
The solution of this problem is not code, rather a configuration and adjustment to the server. The journey to find the solution was very interesting. I removed the CFFORM validation and tried to use simple form. No Luck! I uploaded the same code to another server on different domain, it worked fine. I re-wrote the CFFORM to regular HTML FORM and JavaScript validation. It worked fine. Well, it determines that Code was perfect but the there is something about CFFORM is not working. Carefully, observing the code, which is generated using CFFORM, I see following line of code.

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="/CFIDE/scripts/cfform.js"></SCRIPT>

I played with that and I realize that cfform.js was physically there but missing as relative path for server. I checked the ColdFusion Administrator it was missing the path there.

I) I went to IIS & then map my CFIDE folder under my Web Site giving the alias as CFIDE.

II) After that I created mapping to my CFIDE folder in ColdFusion Administrator

III) I added new path like

Logical Path:/CFIDE

Directory Path: Z:\Inetpub\wwwroot\CFIDE

IV) Restart the ColdFusion Server.

CFFORM validation worked!

Result:
The solution will work when there is a lot of code using CFFORM on the server and “Object Expected” error occurs. This solution will help to fix the problem right away.

I highly recommended writing the code which does not use CFFORM. Please write your own HTML form and JavaScript validation; which gives far great control on that form element.

Online Reference:
ColdFusion MX 6.1: Hot fix for cfform controls
http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_18951