CFWindow Naming Gotcha

Published By: Scott Stroz on Feb 22, 2008 at 11:36 AM

Times Viewed: 754

Categories: ColdFusion

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 <cfgrid> 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 <cfwindow>.  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 sine 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 <cfgrid> was. Now, how did that happen?  Well, the answer to that question is quite simple.

Here is what the code looked like for the <cfgrid>. 

<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" />
    </cfgrid>
</cfform>

 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} ...
</cfform>

 Can you see it?  Do you see the problem?  As soon s I saw that the <cfgrid> was posting instead of the user form, it tipped me off.  When the <cfwindow> is open, there are 2 forms named "userForm" on the page, causing the <cfgrid> 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 <cfform> 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. 

2 Comments

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

Posted By: Michael White on Feb 26, 2008

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

Posted By: Leontyne Williams on Feb 27, 2008

Add a Comment

Please provide your email address if you want to subscribe to this blog entry. An unsubscribe link is provided in notification emails. Your email address is never shown on this website.
Processing... Please wait
We are adding your comment.