0

/t5/coldfusion-discussions/submit-form-and-execute-coldfusion-function/td-p/421101
Oct 10, 2007
Oct 10, 2007
Copy link to clipboard
Copied
Hello!
I have a coldfusion form. What I need to be able to do is submit the form and have it execute a ColdFusion function that I have defined. Can this be done? If so, how?
I know it can be done with a JavaScript function.
Thanks!
I have a coldfusion form. What I need to be able to do is submit the form and have it execute a ColdFusion function that I have defined. Can this be done? If so, how?
I know it can be done with a JavaScript function.
Thanks!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
LEGEND
,
Oct 10, 2007
Oct 10, 2007
<cfscript>
function saveResults () {
<cfset gotourl = "saveresults.cfm/link?query=" & sql>
<cflocation url = gotourl>
}
</cfscript>
<cfform name="saveresults"
action=" http://pluto2/brandi/serverstats/saveresults.cfm" method="post">
<input type="submit" name="Submit" value="Save results as Excel
spreadsheet">
</cfform>
Your function serves no purpose as I understand your requirements. The
action of the form will determine what resource the submit action
requests. Do to the stateless...
function saveResults () {
<cfset gotourl = "saveresults.cfm/link?query=" & sql>
<cflocation url = gotourl>
}
</cfscript>
<cfform name="saveresults"
action=" http://pluto2/brandi/serverstats/saveresults.cfm" method="post">
<input type="submit" name="Submit" value="Save results as Excel
spreadsheet">
</cfform>
Your function serves no purpose as I understand your requirements. The
action of the form will determine what resource the submit action
requests. Do to the stateless...
LEGEND
,
/t5/coldfusion-discussions/submit-form-and-execute-coldfusion-function/m-p/421102#M38000
Oct 10, 2007
Oct 10, 2007
Copy link to clipboard
Copied
"I have a coldfusion form. What I need to be able to do is
submit the
form and have it execute a ColdFusion function that I have defined. Can
this be done? If so, how?
I know it can be done with a JavaScript function."
Yes, if you in someway send a request to the server to run the CF
function. CFML runs on the server and JavaScript runs on the client and
never the two will meet. Using modern techniques such as AJAX one can
make it look to the user that they are, but under the hood CFML is
always confined to the server and JavaScript the client.
More details on what you are trying to do would help.
form and have it execute a ColdFusion function that I have defined. Can
this be done? If so, how?
I know it can be done with a JavaScript function."
Yes, if you in someway send a request to the server to run the CF
function. CFML runs on the server and JavaScript runs on the client and
never the two will meet. Using modern techniques such as AJAX one can
make it look to the user that they are, but under the hood CFML is
always confined to the server and JavaScript the client.
More details on what you are trying to do would help.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/coldfusion-discussions/submit-form-and-execute-coldfusion-function/m-p/421103#M38001
Oct 10, 2007
Oct 10, 2007
Copy link to clipboard
Copied
This page displays a query that is sent via the url.
The form at the bottom contains a button that, when clicked, I want to execute the saveResults() function that re-directs to another coldfusion page where I have code that will save the query results as an xml file (which you so graciously assisted me with earlier today 😃 ).
Or, perhaps, there is a much easier way of doing this and I am just creating too much work. Any suggestions are appreciated.
Code below...
<cfscript> setEncoding("URL", "Shift_JIS"); </cfscript>
<cfset sql = URL.query>
<cfoutput>#sql#</cfoutput>
<cfquery name = "query" datasource = "site"> #replaceNoCase(sql, "''", "'", "all")# </cfquery>
<cfdump var="#query#"></cfdump>
<cfscript>
function saveResults () {
<cfset gotourl = "saveresults.cfm/link?query=" & sql>
<cflocation url = gotourl>
}
</cfscript>
<cfform name="saveresults" action="" method="post">
<input type="submit" name="Submit" value="Save results as Excel spreadsheet">
</cfform>
The form at the bottom contains a button that, when clicked, I want to execute the saveResults() function that re-directs to another coldfusion page where I have code that will save the query results as an xml file (which you so graciously assisted me with earlier today 😃 ).
Or, perhaps, there is a much easier way of doing this and I am just creating too much work. Any suggestions are appreciated.
Code below...
<cfscript> setEncoding("URL", "Shift_JIS"); </cfscript>
<cfset sql = URL.query>
<cfoutput>#sql#</cfoutput>
<cfquery name = "query" datasource = "site"> #replaceNoCase(sql, "''", "'", "all")# </cfquery>
<cfdump var="#query#"></cfdump>
<cfscript>
function saveResults () {
<cfset gotourl = "saveresults.cfm/link?query=" & sql>
<cflocation url = gotourl>
}
</cfscript>
<cfform name="saveresults" action="" method="post">
<input type="submit" name="Submit" value="Save results as Excel spreadsheet">
</cfform>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/submit-form-and-execute-coldfusion-function/m-p/421104#M38002
Oct 10, 2007
Oct 10, 2007
Copy link to clipboard
Copied
<cfscript>
function saveResults () {
<cfset gotourl = "saveresults.cfm/link?query=" & sql>
<cflocation url = gotourl>
}
</cfscript>
<cfform name="saveresults"
action=" http://pluto2/brandi/serverstats/saveresults.cfm" method="post">
<input type="submit" name="Submit" value="Save results as Excel
spreadsheet">
</cfform>
Your function serves no purpose as I understand your requirements. The
action of the form will determine what resource the submit action
requests. Do to the stateless nature of HTTP reqeusts/ & resposnes,
that resource will have no information from this request unless you do
something to pass it along.
The solution that requires the smallest change to your code is simply
put the appropriate information from the function into the form action.
<cfoutput>
<cfform name="saveresults"
action=" http://pluto2/brandi/serverstats/saveresults.cfm/link?query=#sql#"
method="post">
<input type="submit" name="Submit" value="Save results as Excel
spreadsheet">
</cfform>
</cfoutput>
If you are open to more significant modification to your code, it could
probably be simplified and more preformant with the use of persistent
scopes such as session and|or application to store the results and|or
the sql data so that the second request that uses the exact same data
does not have to regenerate it.
function saveResults () {
<cfset gotourl = "saveresults.cfm/link?query=" & sql>
<cflocation url = gotourl>
}
</cfscript>
<cfform name="saveresults"
action=" http://pluto2/brandi/serverstats/saveresults.cfm" method="post">
<input type="submit" name="Submit" value="Save results as Excel
spreadsheet">
</cfform>
Your function serves no purpose as I understand your requirements. The
action of the form will determine what resource the submit action
requests. Do to the stateless nature of HTTP reqeusts/ & resposnes,
that resource will have no information from this request unless you do
something to pass it along.
The solution that requires the smallest change to your code is simply
put the appropriate information from the function into the form action.
<cfoutput>
<cfform name="saveresults"
action=" http://pluto2/brandi/serverstats/saveresults.cfm/link?query=#sql#"
method="post">
<input type="submit" name="Submit" value="Save results as Excel
spreadsheet">
</cfform>
</cfoutput>
If you are open to more significant modification to your code, it could
probably be simplified and more preformant with the use of persistent
scopes such as session and|or application to store the results and|or
the sql data so that the second request that uses the exact same data
does not have to regenerate it.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/coldfusion-discussions/submit-form-and-execute-coldfusion-function/m-p/421105#M38003
Oct 11, 2007
Oct 11, 2007
Copy link to clipboard
Copied
Thanks Ian!
I am open to anything that makes my code better and more efficient - I'm no CF expert as I'm sure you can tell so help and advice is always appreciated.
I am open to anything that makes my code better and more efficient - I'm no CF expert as I'm sure you can tell so help and advice is always appreciated.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/coldfusion-discussions/submit-form-and-execute-coldfusion-function/m-p/421106#M38004
Oct 11, 2007
Oct 11, 2007
Copy link to clipboard
Copied
Now here's some interesting behavior...
I made the changes you suggested:
<cfform name="saveresults" action=" http://pluto2/brandi/serverstats/saveresults.cfm/link?query=#sql#" method="post">
<input type="submit" name="Submit" value="Save results as Excel spreadsheet">
</cfform>
But when it redirects I the page displays '500 null'.
I tried commenting out the piece of code in results.cfm that gets the data from the url and directing it only to saveresults.cfm:
<cfform name="saveresults" action=" http://pluto2/brandi/serverstats/saveresults.cfm" method="post">
and it worked just fine.
Any idea what might be causing this?
I made the changes you suggested:
<cfform name="saveresults" action=" http://pluto2/brandi/serverstats/saveresults.cfm/link?query=#sql#" method="post">
<input type="submit" name="Submit" value="Save results as Excel spreadsheet">
</cfform>
But when it redirects I the page displays '500 null'.
I tried commenting out the piece of code in results.cfm that gets the data from the url and directing it only to saveresults.cfm:
<cfform name="saveresults" action=" http://pluto2/brandi/serverstats/saveresults.cfm" method="post">
and it worked just fine.
Any idea what might be causing this?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/coldfusion-discussions/submit-form-and-execute-coldfusion-function/m-p/421107#M38005
Oct 11, 2007
Oct 11, 2007
Copy link to clipboard
Copied
Any idea what might be causing this?
I should have thought about the kind of data you are sending through the
URL. A complex string such as a sql statement would need to be encoded
to pass through a URL.
" http://pluto2/brandi/serverstats/saveresults.cfm/link?query=#URLEncodedFormat(sql)#"
I would have approached this problem form a different angle. I would
run the query and store the results in a session variable. Then I could
just go to the 'saveresults.cfm' page and access the results from the
session scope and not have to pass the sql statement through or run the
query again.
I should have thought about the kind of data you are sending through the
URL. A complex string such as a sql statement would need to be encoded
to pass through a URL.
" http://pluto2/brandi/serverstats/saveresults.cfm/link?query=#URLEncodedFormat(sql)#"
I would have approached this problem form a different angle. I would
run the query and store the results in a session variable. Then I could
just go to the 'saveresults.cfm' page and access the results from the
session scope and not have to pass the sql statement through or run the
query again.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

