Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations danielledunham on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having a form button run cfquery code

Status
Not open for further replies.

irod

MIS
Jul 29, 2004
7
US
I have a form with a few fields. I want to add a button that will run a cfquery when clicked and use values specified in certain fields. This is a separate process from the form submit button.
 
You could use js to open a pop up window passing all the values via url, run the query using #url.foo# then close the window.
or (this is how I would do it) you could just handle it as a submit button only check the value of it. if it isn't the "actual" submit button just do the small stuff. if it is the "actual" have it do the full processing.

I do this on several pages, here is an example for you.
both buttons are submit buttons with the name of "submit" one has a value of "submit" the other "run query"
on the page you specified as your forms action page do the following.
<cfif isdefined("form.submit") and form.submit = "run query">
do the little stuff
<cflocation url = "theFormPage.cfm">
</cfif>
<cfif isdefined("form.submit") and form.submit = "submit">
Do all the actual stuff you want this form to do.
</cfif>

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Bombboy,

Thanks for the input. The jscript would work, but I've had problems sending the value of the fields.

The submit sounds like a good idea, but If I send it to the action page then am I able to preserve the inputted data on the fields so that the user doesn't have to re-enter the text again in the event that it needs to be sent back to the initial form page?

Thanks again.
 
What I like to do is submit to the same page the form is on for this exact reason. follow me we'll go for a walk...

<cfif isdefined("form.submit") and form.submit eq "run query">
do small stuff
</cfif>
<cfif isdefined("form.submit") and form.submit eq "submit">
do all the real stuff
<cflocation url = "nextPage.cfm">
</cfif>
<html>
..
..
..
<form name = "formName" action = "thisPage" method = "post">
<cfoutput>
<input type = "text" name = "textBox1" value = "<cfif isdefined("form.textBox1")> #form.textBox1#<cfelse>#query.field#</cfif>">
</cfoutput>
...
...
...
</form>
..
..
</html>
notice when the "run query" condition is met it remains on the current page. that allows you to do the check inside the value of the form field. The <cfelse>#query.field# assumes you were previously showing data from a database and should be substuted with the correct names.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Bombboy, thanks for all of your help. I follow what you're saying. I think this solution will solve part of my problem.

I'm trying now to figure out the SQL syntax for date ranges. I have another thread232-905717 in this forum which is kicking my butt. If you wish to please take a look at it.

Thanks again.
 
Bammy217 provided an answer that would work, as far as i can understand your question...

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top