Changes between Version 6 and Version 7 of QuickStart/3:BuildingaForm

Show
Ignore:
Timestamp:
12/02/09 15:36:53 (16 years ago)
Author:
DanWilson (IP: 71.77.43.34)
Comment:

removed the references to the viewstate and added a linkTo

Legend:

Unmodified
Added
Removed
Modified
  • QuickStart/3:BuildingaForm

    v6 v7  
    1111 
    1212{{{ 
    13 <cfset submit = viewstate.getValue("myself") & viewstate.getValue("xe.translate") /> 
     13<cfset submit = event.linkTo( event.getValue("xe.translate") ) /> 
    1414 
    1515<cfform action="#submit#"> 
    16     <cfinput type="text" name="phrase" required="false" value="#viewstate.getValue("phrase")#" /> 
     16    <cfinput type="text" name="phrase" required="false" value="#event.getValue("phrase")#" /> 
    1717    <input type="submit" value="Ok" /> 
    1818</cfform> 
    1919}}} 
    2020 
    21 Ok - what's with this "viewstate" stuff? 
     21Ok - what's with this "event" stuff? 
    2222 
    23 Whenever you're writing a .CFM view, there are two variables always available: "viewstate" and "viewcollection." We'll get to viewcollection in a bit, but here's the rundown on viewstate: 
    24  Viewstate:: 
    25   A viewstate contains all the variables FORM and URL scopes as well as any other values added by the framework. 
    26 The viewstate contains data like a query from a database or (big surprise) the translated version of the phrase that we're asking the user to enter. 
     23Whenever you're writing a .CFM view, there are two variables always available: "event" and "viewcollection." We'll get to viewcollection in a bit, but here's the rundown on event: 
     24 Event:: 
     25  An event object contains all the variables FORM and URL scopes as well as any other values added by the framework. 
     26The event object contains data like a query from a database or (big surprise) the translated version of the phrase that we're asking the user to enter. 
    2727 
    28 To get to one of the variables, you ask the viewstate variable to "get its value" with the getValue() function. 
     28To get to one of the variables, you ask the event object to "get its value" with the getValue() function. 
    2929 
    30 There are a few "default" variables added to viewstate you need to be aware of: 
     30There are a few "default" variables added to event object you need to be aware of: 
    3131 
    3232  * "myself" is the URL of the current page with "?event=" added to it, such as "index.cfm?event=" 
     
    3535  * "eventValue" is the name of the URL variable that contains the current event. Don't worry about this one much, either. 
    3636 
    37 Therefore, the first line in that frmPhrase.cfm says "set the value of the submit variable, which is the action value of the form, to whatever URL you get when you combine index.cfm?event= with the value of a viewstate variable named 'xe.translate'" 
     37Therefore, the first line in that frmPhrase.cfm says "make me a link please, and use the value in the event object for 'xe.translate' as the name of the event." 
    3838 
    3939So what's with this "xe.translate" value? "XE" stands for "eXit Event," and has emerged as a best practice in Model-Glue applications (because it's taken from a best practice in Fusebox!). It lets us reuse this view in multiple places because we determine the action page of the form at runtime, instead of hard coding it into our .CFM template.