The amazing adventures of Doug Hughes

CFWindow Naming Gotcha

I am working on a small application that can be used to demonstrate some of the AJAX capabilities of ColdFusion 8. It is a simple master/detail application for managing information about users. The main page uses to display the list of users. When you want to edit a user, or create a new one, I use the ColdFusion.navigate() JavaScript method to load a URL into a . This page contains the user form.

Whenever I created or edited a user, it would work as expected…the first time. The next time I would try to edit or create a user and submit the form, I would get an error from ColdFusion stating that one of the form fields was missing. Huh? How is that possible since the form just worked?

Using FireBug I was able to look at the POST of the form submission. On the instances where I would receive the error, sure enough, the form fields were not getting posted, but, the was. Now, how did that happen? Well, the answer to that question is quite simple.

Here is what the code looked like for the :

<cfform name="userGridForm" method="post">
	<cfgrid name="userGrid" ......... >
		<cfgridcolumn name="USERID" header="ID" display="false" />
		<cfgridcolumn name="FIRSTNAME" header="First Name" width="200" />
		<cfgridcolumn name="LASTNAME" header="Last Name" width="300" />
		<cfgridcolumn name="EMAILADDRESS" header="Email" width="220" />
		<cfgridcolumn name="PHONE" header="Phone" />

Here is what the code looked like in the user form, which was a seperate file:

<cfform name="userForm">
	<cfinput type="hidden" name="userId"....../>
	... {more form fields} ...

Can you see it? Do you see the problem? As soon as I saw that the was posting instead of the user form, it tipped me off. When the is open, there are 2 forms named userForm” on the page, causing the to be submitted sometimes, and the user form others. Why it did not error out everytime I tried to save a user is beyond me. Changing the name to “userGridForm” on the mian page cleared up the issue.

Remember, even though you are in a different physical file, naming can cause issues, especially when using them as I did in this litle demo.

Comments on: "CFWindow Naming Gotcha" (2)

  1. Michael White said:

    when I saw the title I thought you were talking about the name attribute of the cfwindow tag. I was trying to use a cfwindow but didn’t know how to test if a cfwindow with that name already existed so I ended up using ColdFusion.Window.create instead


  2. Leontyne Williams said:

    I need to do something similar to what you are doing here. I am using a flash form, and need to popup a window to enter or update detail information that will update back to the master table.

    When I use it tells me I need to use the cfajaximport tag for cfwindow….which I have done at the top of the calling page…and again at the top of the called page (where the detail information entered/updated).

    I’m new to flash/ajax…I have used cf5 for many years. The new techniques are overwhelming me.

    Thanks for your help.


Comments are closed.

Tag Cloud

%d bloggers like this: