Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


ColdFusion Self-Submitting Forms?

ColdFusion Self-Submitting Forms?

ColdFusion Self-Submitting Forms?


Can anyone illustrate clearly the method for self-submitting a form, such that the form submission and processing are done on one template, (standard HTML forms and/or <CFFORM>? I know it must be relatively easy but I have some kind of mental block against it, having learned CF using exclusively 2-template form processing.



RE: ColdFusion Self-Submitting Forms?

Add after closing the form tag:


Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic

RE: ColdFusion Self-Submitting Forms?

Hi mate,

If I understand your question correctly then you need the following:

<cfif isDefined("process_it")>

Code to process form here


Form code here

Make sure the following field is in your form.

<input type="hidden" name="process_it" value="1">


Hope this helps



The pessimist complains about the wind.  The optimist expects it to change.
The leader adjusts the sails. - John Maxwell

RE: ColdFusion Self-Submitting Forms?

Okay... I thought I understood your question, RockyRoad, but after reading the responses I think maybe I'm missing something.

You're asking how to set up a single CFM page with a form so that it submits to itself, and, following that, how to tell that the form's been submitted so you can act on it, right?

If so, as you say, it's relatively easy. The key is realizing that the value of the submit button is passed as one of the form variables... just like everything else on the form.

So you would set up something like:

<!--- set up some CFPARAMs so we can have some defaults --->
<CFPARAM name="FORM.firstname" default="">
<CFPARAM name="FORM.lastname" default="">

<CFIF IsDefined("FORM.submit") AND CompareNoCase(FORM.submit,"Do it!") EQ 0>
   <!--- the form was submitted, act on it however you like, including doing selects, inserts, or just CFOUTPUTs --->

   Thank you, <CFOUTPUT>#FORM.firstname# #FORM.lastname#</CFOUTPUT> for submitting the form!


<form action="#GetFileFromPath(GetBaseTemplatePath())#" method="POST">
    <p>First name:<br />
    <!--- include the most recent value of the submitted form, if you like, by simply setting the value to the variable --->
    <input type="text" name="firstname" value="#FORM.firstname#"></p>
    <p>Last name:<br />
    <input type="text" name="lastname" value="#FORM.lastname#"></p>

    <p><input type="submit" name="submit" value="Do it!"></p>

The above redisplays the form when it's been submitted. This is one of the chief benefits of submitting to itself. But, if you don't want the form to display again, you can always replace the </CFIF> with a <CFELSE> so that the form is wrapped in a block that would only execute if the form hasn't been submitted yet.

Is that what you had in mind?


RE: ColdFusion Self-Submitting Forms?

Also here is a way of getting the select option to be selected when it comes back to the page.

to test: http://www.gatorstudios.com/myorganizer/test.cfm

<cfparam name="Form.selectit" default="This">
<cfset optionlist="This,That,Whatever">
<cfset sel="">
<title>Select Option</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<form name="form1" method="post" action="test.cfm">
  <table width="309" height="23" border="0" cellpadding="0" cellspacing="0">
    <td width="199" align="right">Select Something:</td>
    <td width="110">
    <select name="selectit">
        <cfloop index="opt" list="#OptionList#" delimiters=",">
            <cfif opt is Form.SelectIt><cfset sel = "selected"></cfif>
            <cfoutput><option #sel#>#opt#</option></cfoutput>
            <cfset sel="">
    <input type="submit" name="Submit" value="Submit">

RE: ColdFusion Self-Submitting Forms?




Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close