Skip to main content
June 23, 2009
Question

Return to Form

  • June 23, 2009
  • 1 reply
  • 1534 views

What is the best way to flush a form after submitting data to a database, and return to the form?  I have not been able to find any examples of this.

Thank you,

Jeanne

This topic has been closed for replies.

1 reply

ilssac
Inspiring
June 23, 2009

What do you mean 'flush' and what do you mean by 'return'.

It all depends on how you want your application to flow.

If you use the normal receive form post request, process request, return response of the same form.  You will have an new empty form, assuming your applicaiton does not do something to restore the state of the data previously submitted.

If you use some type of HTTP 'back' that sends the browser back a request, the form is going to be populted.

June 23, 2009

Here are the form and action.cfm.  I did not set up an Application.cfm.  Perhaps I need to?  I added some Javascript at the bottom of the action.cfm to return to the form, but it is being igored???

Thanks,

Jeanne

************************************************

<html>
<head>
<title>CAF Survey Form</title>
</head>
<body bgcolor="#CCFFFF">
<h2 align="center">Enter a CAF Survey Form</h2><br>

<cfform action="surveyAction.cfm" method="post">

<script language="JavaScript">
<!--
document.location.href = "http://localhost:8500/cafsurvey/surveyForm.cfm;
//-->
</script>

<table>
<tr>
<td width="33">
</td>
<td>

Date:
<cfinput type="text" name="SURVEY_DATE" size="10" maxlength="10">            

Branch:
<cfinput type="text" name="BRANCH" size="4" maxlength="4"><br><br><br>

1. Did you get what you needed today?                                          
<cfinput type="radio" name="NEED_FLG" id="radio" value="Y">Yes
<cfinput type="radio" name="NEED_FLG" id="radio" value="N">No
<cfinput type="radio" name="NEED_FLG" id="radio" value="X">Did Not Answer<br><br>

          If not, please explain:  
<cftextarea name="NEED_COMMENT" wrap="virtual" rows="5" cols="25"
validate="maxlength" validateAt="onBlur" maxlength="200" onKeyDown="limitText('comments','countdown_comments',200)">
</cftextarea><br><br><br>

2. Did you receive information about other community resources?   
<cfinput type="radio" name="RESOURCE_FLG" id="radio" value="Y">Yes
<cfinput type="radio" name="RESOURCE_FLG" id="radio" value="N">No
<cfinput type="radio" name="RESOURCE_FLG" id="radio" value="X">Did Not Answer<br><br><br>

3. How long did you wait in the office to be seen today?              Minutes     Hours
   Did Not Answer<br>                                                                                                 
<cfinput type="text" name="WAIT_MIN" size="2" maxlength="2">   
<cfinput type="text" name="WAIT_HRS" size="2" maxlength="2">        
<cfinput type="checkbox" name="WAIT_FLG" value="X"><br><br><br>

4. How long did it take to get today's appointment??          Hours        Days      Weeks
   Did Not Answer<br>                                                                                       
<cfinput type="text" name="APPT_HRS" size="2" maxlength="2">   
<cfinput type="text" name="APPT_DAYS" size="2" maxlength="2">   
<cfinput type="text" name="APPT_WEEKS" size="2" maxlength="2">        
<cfinput type="checkbox" name="APPT_FLG" value="X"><br><br><br>

5. Did you have enough time during your appointment to <br>
   tell your case worker what you wanted or needed?                    
<cfinput type="radio" name="TIME_FLG" id="radio" value="Y">Yes
<cfinput type="radio" name="TIME_FLG" id="radio" value="N">No
<cfinput type="radio" name="TIME_FLG" id="radio" value="X">Did Not Answer <br><br>

          If not, please explain:  
<cftextarea name="TIME_COMMENT" wrap="virtual" rows="5" cols="25"
validate="maxlength" validateAt="onBlur" maxlength="200" onKeyDown="limitText('comments','countdown_comments',200)">
</cftextarea><br><br><br>

6. Did you get all of your questions answered?                             
<cfinput type="radio" name="ANSWERS_FLG" id="radio" value="Y">Yes
<cfinput type="radio" name="ANSWERS_FLG" id="radio" value="N">No
<cfinput type="radio" name="ANSWERS_FLG" id="radio" value="X">Did Not Answer<br><br>

          If not, please explain:  
<cftextarea name="ANSWERS_COMMENT" wrap="virtual" rows="5" cols="25"
validate="maxlength" validateAt="onBlur" maxlength="200" onKeyDown="limitText('comments','countdown_comments',200)">
</cftextarea><br><br><br>

7. How was the service today?                                                   
<cfinput type="radio" name="SERVICE_FLG" id="radio" value="Y">Yes
<cfinput type="radio" name="SERVICE_FLG" id="radio" value="N">No
<cfinput type="radio" name="SERVICE_FLG" id="radio" value="X">Did Not Answer<br><br>

                        Comments:  
<cftextarea name="SERVICE_COMMENT" wrap="virtual" rows="5" cols="25"
validate="maxlength" validateAt="onBlur" maxlength="200" onKeyDown="limitText('comments','countdown_comments',200)">
</cftextarea><br><br><br>

8. Would you like to share any other information about your visit today?<br><br>
                                            <cftextarea name="OTHER_INFO" wrap="virtual" rows="5" cols="25"
validate="maxlength" validateAt="onBlur" maxlength="200" onKeyDown="limitText('comments','countdown_comments',200)">
</cftextarea><br><br><br>

9. Are there any unresolved issues that you would <br>
   like to have addressed?                                                           
<cfinput type="radio" name="UNRESOLVED_FLG" id="radio" value="Y">Yes
<cfinput type="radio" name="UNRESOLVED_FLG" id="radio" value="N">No
<cfinput type="radio" name="UNRESOLVED_FLG" id="radio" value="X">Did Not Answer<br><br><br>

If you would like someone to contact you, please include your name and phone number:<br><br>          
Name: <cfinput type="text" name="CONTACT_NAME" size="40" maxlength="40">     
Phone: <cfinput type="text" name="CONTACT_PHONE" size="10" maxlength="10">


<!--- <cftextarea name="NEED_COMMENT" height="3" width="800" size="200" maxlength="200"></cftextarea> --->

<!--- <textarea name="Needcomments" cols="50" rows="3" id="Needcomments" tabindex="35" onFocus="this.rows=4" onBlur="this.rows=1" onSelect="this.rows=4" onKeyDown="limitText('comments','countdown_comments',200);" onKeyUp="limitText('comments','countdown_comments',200);"> </textarea> --->

<br><br><br>
<input type="Submit" value="Submit">          <input type="Reset"
value="Clear Form">


</td>
</table>

</cfform>

</body>
</html>

**********************************************************

<html>
<head> <title>Insert Survey Form</title> </head>
<body>

<!--- Insert the new record --->

<cfset needCom = left(NEED_COMMENT,200)>
<cfset timeCom = left(TIME_COMMENT,200)>
<cfset answersCom = left(ANSWERS_COMMENT,200)>
<cfset serviceCom = left(SERVICE_COMMENT,200)>
<cfset otherInfo = left(OTHER_INFO,200)>

<cfif isdefined ("form.WAIT_FLG")>
<cfset form.WAIT_FLG = "X">
<cfelse>
<cfset form.WAIT_FLG = "N">
</cfif>

<cfif isdefined ("form.APPT_FLG")>
<cfset form.APPT_FLG = "X">
<cfelse>
<cfset form.APPT_FLG = "N">
</cfif>

<cfquery datasource="AXMISC_SURVEY">
   INSERT INTO SURVEY.CAF_SURVEY
   (SURVEY_DATE, BRANCH, NEED_FLG, NEED_COMMENT, RESOURCE_FLG, WAIT_MIN, WAIT_HRS, WAIT_FLG, APPT_HRS, APPT_DAYS, APPT_WEEKS, APPT_FLG, TIME_FLG, TIME_COMMENT, ANSWERS_FLG, ANSWERS_COMMENT, SERVICE_FLG, SERVICE_COMMENT, OTHER_INFO, UNRESOLVED_FLG, CONTACT_NAME, CONTACT_PHONE)
   VALUES
   ( <cfqueryparam cfsqltype="cf_sql_date" value="#form.SURVEY_DATE#">,
     <cfqueryparam cfsqltype="cf_sql_char" value="#form.BRANCH#">,
     <cfqueryparam cfsqltype="cf_sql_char" value="#form.NEED_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#needCom#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.RESOURCE_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.WAIT_MIN#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.WAIT_HRS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.WAIT_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_HRS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_DAYS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_WEEKS#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.APPT_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.TIME_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#timeCom#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.ANSWERS_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#answersCom#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.SERVICE_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#serviceCom#>,
  <cfqueryparam cfsqltype="cf_sql_varchar" value=#otherInfo#>,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.UNRESOLVED_FLG#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.CONTACT_NAME#">,
  <cfqueryparam cfsqltype="cf_sql_char" value="#form.CONTACT_PHONE#">
   )
</cfquery>

<script language="JavaScript">
<!--
document.location.href = "http://localhost:8500/cafsurvey/surveyForm.cfm;
//-->
</script>

<!--- <cfoutput>You have added #CONTACT_NAME# to the
Client Survey database.
</cfoutput>   --->
</body>
</html>

***************************************

ilssac
Inspiring
June 23, 2009

One does usually use client side java script code to control server side application flow.

This code shows a common new CF developer who does not yet understand the client-server nature of ColdFusion applications.  In important thought to keep in mind is that parts of each web application runs on two completely seperate computers that do not share resources.  CFML runs on the server.  JavaScript runs on the Client and never will the two meet.

Usually this turns up with new developers trying to figure out why variables on CFML can not be read by JavaScript on the client or vice-a-versa.

The simpliest solution to your problem is to replace your JavaScript redirect with a CFML <cflocation...> redirect.  Better logic might be to use a <cfinclude...> or some other method that incorperates the form into the same request so that no redirect is required at all.