Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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>
***************************************
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Do you have any examples?
Thanks,
Jeanne
Copy link to clipboard
Copied
No, but the internet does.
fordwebs.com ColdFusion form tutorial
http://www.fordwebs.com/cfform.cfm
First link from my Google Search for "ColdFusion Form Tutorial"
http://www.google.com/search?q=coldfusion+form+tutorial&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
Copy link to clipboard
Copied
That is one of the big problems with ColdFusion. Functionality.
I have two Ben Forte tomes, and cannot find a snippet of code that shows show to return to a form once it is processed.
I contacted two Adobe Certified training centers, one cannot find any other students to take a course, so they offer none. The other one had a phone message that they were out of town, instructing me to email them, which I did a month ago and did not hear back from them. I have spent countless hours searching the "Developers Guide" and "CF Reference", searching the Adobe site (not very successfully), and the internet to figure out how to do simple tasks.
Where does one go for straightforward information - that does not consume hours finding simple answers?
Copy link to clipboard
Copied
I've always relied on the documentation that came free with the installer. It is also freely available on the internets.
http://livedocs.adobe.com/coldfusion/8
A couple of clicks through to "Flow Control Tags" would turn up a nice list of availble options.
http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags-pt0_12.html#2459878
This includes the often used <cflocation...> tag.
http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_j-l_04.html#1100753
I suspect your dificulty here is that your questions, this one at least, is ColdFusion Web Applicaiton Development 101 that is not going to get topics of its own.
You have a form page.
You have an action page.
You <cflocation....> or <cfinclude...> the form page if you want to present it again.
OR
You have the action page as part of the form page that is conditionally processed when the form is submitted.
OR
You encorperate any number of frameworks that handle this for you and use the frameworks syntax for plugging in form user intervace views and action page models and whatever controlers you want to get from one to the other and back again.
----------
The first options are the stuff you are going to find in "My First ColdFusion" topics, include the beginnng chapters of those Ben Forta books you have, and most more advanced topics are going to assume you already know this. But if one has experience with other web technologies, one often skips such rudimentary chapters when picking up a new technology.