Skip to main content
Participant
March 11, 2010
Answered

coldfusion processing on submit question

  • March 11, 2010
  • 3 replies
  • 1582 views

Could someone explain coldfusion processing to me. This example from the documentation implies that the <ciif will be executed when the submit occurs. But doesn't the server just process the form on a submit ? I don't understand how the <cfif gets executed. Thanks

<h3>cfmail Example</h3>

<!--- Delete the surrounding comments to use this example.

<cfif IsDefined("form.mailto")>
    <cfif form.mailto is not "" AND form.mailfrom is not "" AND form.Subject is not "">
        <cfmail to = "#form.mailto#" from = "#form.mailFrom#" subject = "#form.subject#">
                This message was sent by an automatic mailer built with cfmail:
                = = = = = = = = = = = = = = = = = = = = = = = = = = =
                #form.body#
        </cfmail>    
        <h3>Thank you</h3>
        <p>Thank you, <cfoutput>#mailfrom#: your message, #subject#, has been sent to
            #mailto#</cfoutput>.</p>
    </cfif>    
</cfif>
<p>
<form action = "cfmail.cfm" method="POST">
    <pre>
    TO: <input type = "Text" name = "MailTo">
    FROM: <input type = "Text" name = "MailFrom">
    SUBJECT:     <input type = "Text" name = "Subject">
    <hr>
    MESSAGE BODY:
    <textarea name ="body" cols="40" rows="5" wrap="virtual"></textarea>
    </pre>
    <!--- Establish required fields. --->
    <input type = "hidden" name = "MailTo_required" value = "You must enter a recipient">
    <input type = "hidden" name = "MailFrom_required" value = "You must enter a sender">
    <input type = "hidden" name = "Subject_required" value = "You must enter a subject">
    <input type = "hidden" name = "Body_required" value = "You must enter some text">
    <p><input type = "Submit" name = ""></p>
</p>
</form>

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f8e.html

This topic has been closed for replies.
Correct answer TLC-IT

That example is confusing.  Usually, if a form is going to submit back to itself, the link is either omitted entirely or it is an empty string.

Nevertheless:  directives like <cfif> are executed when a form has been submitted (or a URL has been requested), and ColdFusion is preparing the response.  ColdFusion prepares the response by executing the various directives in the file.

3 replies

Inspiring
March 18, 2010

Let me try again ...

Step one:  you go to a page by typing-in the address or following a hotlink ...

ColdFusion finds the ".cfm" page that you requested and executes (or, processes) it.  Any non-CF content is copied verbatim; all of the CFML tags are executed.  The output from all this is what will be "the web page that the user sees."

Since you followed a hotlink to get here, there is no "submitted FORM data."  The request is of HTTP-type "GET," not "POST."  All of these things are known to you, and to ColdFusion.

Step two:  you fill out an HTML form and press "Submit" ...

The same things happen as before, but this time it is an HTTP "POST" request which contains the data values you typed in.  ColdFusion makes this available in the "FORM.xxx" variable.  From this you know what values the user typed in and what button they pressed.

Various Coldfusion-specific tags such as <cfform> and <cfinput> are designed to make things easier for you.  "Exactly how they work" can vary widely, but the idea is just that, "they work."  While ColdFusion is processing these and the various other CFML tags in your file, it can generate a lot of different things, in a lot of different ways that you don't have to think about, and the entire name of the game is:  "you don't have to think about it."  It might generate JavaScript ... you don't care.  It might do pre-validation of the values that the user submitted ... "so what, it just works."  ColdFusion is a power-tool designed to make easy things easy.  (And sometimes ... ... it does.)

Eventually, just as before, some amount of output is generated as a result of all this, and whatever does get generated is sent back to the user as the new web page that they see.

TLC-ITCorrect answer
Inspiring
March 11, 2010

That example is confusing.  Usually, if a form is going to submit back to itself, the link is either omitted entirely or it is an empty string.

Nevertheless:  directives like <cfif> are executed when a form has been submitted (or a URL has been requested), and ColdFusion is preparing the response.  ColdFusion prepares the response by executing the various directives in the file.

Fernis
Inspiring
March 17, 2010

>> directives like <cfif> are executed when a form has been submitted (or a URL has been requested)

To be absolutely clear on that:

* All coldFusion directives are always processed when a .cfm/.cfml template is read.

* Forms, existing or not, don't affect how ColdFusion processes the template.

The condition between <cfif> and </cfif> tags is processed only if the <cfif condition> results "true".

Your template works, if it's named as "cfmail.cfm" itself. Thus it posts itself back to the same template.

First time when you load the template, there are no variables in the FORM variable scope - assuming you did not come to the template from another form.

When there's a html <form> on the page, and it is submitted, ColdFusion sees the FORM variable scope, having FORM[fieldname] variables present for each form field (except unchecked checkboxes).

Thus, the next time the code between the <cfif> gets executed, because a ColdFusion variable FORM.mailTo (or FORM["mailTo"]) existed.

<cfif isdefined("form")>

<cfdump var="#form#">

</cfif>

will help you dig a bit deeper into form processing and the available variables.

--

- Fernis - fernis.net - ColdFusion Developer For Hire

Participant
March 11, 2010

Oh now I see

action is back to itself