Changes between Version 6 and Version 7 of QuickStart/3:BuildingaForm
- Timestamp:
- 12/02/09 15:36:53 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
QuickStart/3:BuildingaForm
v6 v7 11 11 12 12 {{{ 13 <cfset submit = viewstate.getValue("myself") & viewstate.getValue("xe.translate") />13 <cfset submit = event.linkTo( event.getValue("xe.translate") ) /> 14 14 15 15 <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")#" /> 17 17 <input type="submit" value="Ok" /> 18 18 </cfform> 19 19 }}} 20 20 21 Ok - what's with this " viewstate" stuff?21 Ok - what's with this "event" stuff? 22 22 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 viewstatecontains all the variables FORM and URL scopes as well as any other values added by the framework.26 The viewstatecontains data like a query from a database or (big surprise) the translated version of the phrase that we're asking the user to enter.23 Whenever 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. 26 The 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. 27 27 28 To get to one of the variables, you ask the viewstate variableto "get its value" with the getValue() function.28 To get to one of the variables, you ask the event object to "get its value" with the getValue() function. 29 29 30 There are a few "default" variables added to viewstateyou need to be aware of:30 There are a few "default" variables added to event object you need to be aware of: 31 31 32 32 * "myself" is the URL of the current page with "?event=" added to it, such as "index.cfm?event=" … … 35 35 * "eventValue" is the name of the URL variable that contains the current event. Don't worry about this one much, either. 36 36 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'"37 Therefore, 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." 38 38 39 39 So 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.
![(please configure the [header_logo] section in trac.ini)](/ModelGlue.com/trac.cgi/chrome/site/your_project_logo.png)