ColdFusion TIPS PLUS
Issue 00141 http://www.cftipsplus.com
I. My CommentsII. ColdFusion In Context: Unreal Forms
By R. Martin Ladner
martin.ladner@charter.net
I. Comments:
More Photos of My Family
http://www.milforddel.com/photos/index.cfm
Been busy with the New Baby but enjoying him. He is very cute. Hopefully I can find time to get more pictures on the web. I am still fighting with Comcast to get a Cable Connection at home. DSL is not available where I live. So I am STUCK with a company that does not care.
Martin's wife has had some hard times. She is mending now but not sure if things will ever be the same. I am not sure how much Martin would not want me to say but please keep both of them in your prayers as I have for months now.
Site Status (For Sale)
http://www.cftagstore.com/?page=viewtag&tagId=182
http://www.cfxtras.com/SalesComponentDetail.cfx?componentid=553
Example:
http://www.cftipsplus.com/sitestatus/index.cfm
Documentation:
http://www.cftipsplus.com/sitestatus/help.cfm
Have a good Easter,
Keep Coding,
Nathan Stanford
http://www.cftipsplus.com
If you have suggestions for articles send them to us.
If you would like to write for cftipsplus.com
send us an email to:
NathanS<at>nsnd.com
IF YOU WANT TO BE AN AUTHOR SEND IN YOUR COLDFUSION TIPS.
Remember this is a great way to get your name known in the
ColdFusion Community.
II. ColdFusion in Context: Unreal Forms
By R. Martin Ladner
martin.ladner@charter.net
When you check to see if a form has been submitted, you generally check for the presence of a specific form field that won't have a value until the form has been submitted. It's a good thing you check for a specific variable in a real form; because, there are also... pause... take a deep breath... unreal forms. (Have we missed Halloween?)
Unreal Forms
Put the following code in mystery.cfm. The results may blur your perspective of what a form really is. First, check to see if "form" is defined. If it is, then check to see if "form" is a structure. If it is, then give form.Jack a value. Check to see if form.Jack is defined. Finally, check to see if a variable you haven't named is defined.
<cfif isDefined("form")>
Form is defined.
<cfif isStruct(form)>
Form is a structure.
<cfset form.Jack=92>
</cfif>
</cfif>
<cfif isDefined("form.Jack")>
Jack exists for ColdFusion.
</cfif>
<cfif isDefined("form.Mode")>
Mode is defined.
</cfif>
Browse the page. It says that you already have a form, that form is a structure, and that the structure is so real that you can add variables to it. You know the isDefined function is really working; because, it will tell you that an undefined form variable doesn't exist. Therefore, you have an unreal form.
Real Forms
Add the following code to make a real form. Surround it with cfif tags so you can turn it on and off by simply adding a query string to the URL. Let it submit to the current page by default (not specifying an action). However, be sure to set the method to post. Give it a submit button, and give it a hidden field named Mode.
<cfif isDefined("url.Real")>
<form method="post" name="Frank">
<input type="submit" name="Fred" value="Click Here">
<input type="hidden" name="Mode" value="26">
</form>
</cfif>
Browse mystery.cfm?Real=87 (or give Real any other value you like). You see a submit button. The other results are at first just the same though. Everything you've checked for is defined except for Mode.
Press the submit button. Because you didn't specify an action, the current URL including the current query string becomes the action. Now the form has been submitted and now a field that it created exists. If you remove the query string, the page reverts to its old self.
Implications
It's tempting, once you realize that a form is a structure just like any other structure, to check for the presence of the structure to determine if a form has been submitted. However, as you've just seen, the structure always exists, even if the page doesn't have a form or even if it has an unsubmitted form. This lets you use ColdFusion to assign values to form fields that may be encountered later (if ever). In the past, you checked for the existence of a specific form field, not just the form structure, in order to know if a form had been submitted. Now you know why.
=Marty=
Publisher and Creator:
Nathan Stanford,
NathanS<at>nsnd.com
http://www.cftipsplus.com
Macromedia and ColdFusion are U.S. registered trademarks.
Copyright (c) 2000 - 2004
CFTIPSPLUS.COM and NSND.COM
Permission is granted to circulate this publication via
MANUAL forwarding by email to friends provided that the text is
forwarded in its entirety and no fee is charged.