macromedia.coldfusion.cfml_general_discussion
[Top] [All Lists]

How can I use a cfwindow with a form in it to update the main page?

Subject: How can I use a cfwindow with a form in it to update the main page?
From: "Jeff_Self"
Date: Thu, 30 Aug 2007 15:11:15 +0000 UTC
Newsgroups: macromedia.coldfusion.cfml_general_discussion
This seems simple enough but I can't figure it out.  My main page calls a query 
to get a list of departments.  I have put this list in a table inside a cfdiv 
tag.  I have an add department link on my page.  When the user clicks on this 
link, I want a popup window (cfwindow) to display containing a form to add a 
department.  Then when the user submits the form, the form should disappear and 
the main page should show the updated list of departments.

 I can't get the form to close without getting an error stating that there 
already is a window with that name and the new data doesn't display unless I 
refresh my screen.

 Here's my departments.cfm page:
 <html>
 <head>
 </head>

 <cfinvoke component="department"
                                        method="list"
                                        returnvariable="departments">
 </cfinvoke>

 <body>
        <cfwindow name="deptWindow" title="Department Window" draggable="true" 
resizable="false"
                                                initshow="false" height="400" 
width="600" x=200 y=100>
        <cfform action="processDepartment.cfm" 
onsubmit="ColdFusion.Window.hide('deptWindow')">
                Department:
                <cfinput type="text" name="deptname">
                <cfinput type="submit" name="submit">
        </cfform>
        </cfwindow>

        <a href="#" onClick="ColdFusion.Window.show('deptWindow')">Add 
Department</a>
        <cfdiv>
                <table>
                        <tr>
                                <th>Department</th>
                                <th>Action</th>
                        </tr>
                        <cfoutput query="departments">
                        <tr>
                                <td>#deptname#</td>
                                <td><a href="##" 
onClick="ColdFusion.Window.show('deptWindow')">Edit</a></td>
                        </tr>
                        </cfoutput>
                </table>
        </cfdiv>

 </body>
 </html>

 Here's my department.cfc page:
 <cfcomponent output="false">

        <cfset THIS.dsn="cf8test">
        <cffunction name="list" access="remote" output="false" 
returntype="Query">
                <cfquery name="departments" datasource="#THIS.dsn#">
                        SELECT department_id, deptname
                        FROM departments
                        ORDER by deptname
                </cfquery>
                <cfreturn departments />
        </cffunction>


        <cffunction name="add" access="public" output="false" 
returntype="Boolean">
                <cfargument name="deptname" required="true" type="string">
                <cfquery datasource="#THIS.dsn#">
                        INSERT INTO departments(deptname) 
                        VALUES (<cfqueryparam 
value="#Trim(ARGUMENTS.deptname)#" 
cfsqltype="cf_sql_varchar">)
                </cfquery>
                <cfreturn true />
        </cffunction>
       </cfcomponent>

 And finally, here's my processDepartment.cfm page:

 <!--- Form Field Validation --->
 <cfparam name="FORM.deptname" type="string">

 <cfif IsDefined("FORM.id")>
   <cfset method="update">
 <cfelse>
   <cfset method="add">
 </cfif>


 <cfinvoke component="department"
           method="#method#">
   <cfif IsDefined("FORM.id")>
     <cfinvokeargument name="id"
                       value="#FORM.id#">
   </cfif>
   <cfinvokeargument name="deptname"
                     value="#Trim(FORM.deptname)#">
 </cfinvoke>

 <!--- When done go back to the Departments listing --->

 <cflocation url="/departments.cfm">


<Prev in Thread] Current Thread [Next in Thread>
  • How can I use a cfwindow with a form in it to update the main page?, Jeff_Self <=