Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

ColdFusion Self-Submitting Forms?Helpful Member! 

rockyroad (Programmer) (OP)
11 Apr 03 10:33
Hello,

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.

THANKS!!!!

rr
DeZiner (Programmer)
11 Apr 03 11:15
Add after closing the form tag:

<SCRIPT LANGUAGE="JavaScript">
     document.forms[0].submit();
</SCRIPT>

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

Helpful Member!  Wullie (Programmer)
11 Apr 03 12:12
Hi mate,

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


<cfif isDefined("process_it")>

Code to process form here

<cfelse>

Form code here

Make sure the following field is in your form.

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

</cfif>


Hope this helps

Wullie

www.freshlookdesign.co.uk
www.freshlookdesign.com
www.necomputers.org.uk
www.whiland.co.uk

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

csteinhilber (Programmer)
11 Apr 03 13:03
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!

</CFIF>

<CFOUTPUT>
<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>
</form>
</CFOUTPUT>


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?


-Carl

army001 (Programmer)
11 Apr 03 14:52
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="">
<html>
<head>
<title>Select Option</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="test.cfm">
  <table width="309" height="23" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <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="">
        </cfloop>
    </select>
     </td>
  </tr>
</table>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>
</body>
</html>
rockyroad (Programmer) (OP)
16 Apr 03 17:00
THANKS!

EVERYONE'S INPUT WAS VERY HELPFUL!

RR

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