============== ColdFusion TIPS PLUS ColdFusion 01 Volume 01 Issue 16 =============================================================== http://www.cftipsplus.com ============== Issue 00055 ============== I. Comments: II. ColdFusion In Context: Remote Control By R. Martin Ladner martin.ladner@knology.net III. Uppercase The first letter of a word. Jeff Davis Macromedia Certified Cold Fusion Trainer, Developer Fig Leaf Software jdavis@figleaf.com
IV. process CF Form variables individually Theo den Brinker AIRC/AIR Electronic Publishing theo.denbrinker@air.gov.au
============== I. Comments: I like getting the different authors from different levels of programming and different view points. There are many ways you can approach the same problems.
Keep Coding, Nathan Stanford President/CEO C.F. Concepts, Inc. 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:
admin@cftipsplus.com
IF YOU WANT TO BE AN AUTHOR SEND IN YOUR COLDFUSION TIPS.
Remember this is a great way to get your name know in the ColdFusion Community.
=============================================================== If you have any suggestions please email me at cftips@nsnd.com. ===============================================================
=============================================================== II. ColdFusion In Context: Remote Control By R. Martin Ladner martin.ladner@knology.net
===============================================================
Ever wonder how to be sure your site is awake and still displaying more than static pages? Do you lack the cash for expensive monitoring tools and services? CFHTTP "post" may not understand your application's fancy home page, but you can always create a miniature application that proves your server's awake and reachable by the world.
Here's a short example for your review. It consists of just two files: "light.cfm" (which resides on the server being tested to see if the lights are on ) and "push.cfm" to ring the doorbell, figuratively speaking.
Test the Server A perfect CFHTTP tag would understand JavaScript and would let you specify which submit button to trigger on which of multiple forms of the target URL. However, the existing CFHTTP tag isn't that smart. That's why it's a good idea to create a simple check page for your server instead of expecting CFHTTP to cope with the bells and whistles on the main page you've prepared for your human users.
The following code is a form that calls itself. When you (or the CFHTTP tag from another server) submit a number in the input field, the form automatically adds one to the input and displays the result: proof that you're not looking at a static display.
<cfif isDefined("form.check")> <cfset form.check=#form.check#+1> <cfelse> <cfset form.check=0> </cfif>
If the machine is running, it will increment the number in the form field.<br>
<cfform name="light" action="light.cfm" method="post"> Check: <cfinput name="check" type="text" value="#form.check#"> <input name="doit" type="submit" value="Now"> </cfform>
It would be quick work to modify this code to update a database with the incremented value, read the value back from the database, and pass it back to the form. This would check the database and its connection to the server as well.
For this example, be sure not to leave any spaces after the word "value" in the input field; because, the remote tester is going to count positions from the beginning of this word when it looks for the new value of this field.
Run the Test Remotely When using the CFHTTP tag to post data, there are two oddities which aren't clear from the examples I've seen. First, you don't send a value for the submit tag. (That's one of the reasons for picking a target page that doesn't have multiple submit tags whose value would make a difference to the application.) Second, you do send a value for all other inputs, even those you don't care about. If your "post" from the CFHTTP tag leaves any input fields empty that are present on the remote form, the post will probably fail.
<!--- Point this URL at the system to be monitored ---> <cfhttp url="http://127.0.0.1/light.cfm" method="post" resolveurl="false">
<cfhttpparam type="formfield" name="check" value="8">
</cfhttp>
<html> <head><title>view</title></head><body> <h3>view</h3> <cfoutput> Status code is #cfhttp.statusCode#<br>
<hr> Content is #htmlCodeFormat(cfhttp.fileContent)#<br> </cfoutput>
<cfif findnocase("value",cfhttp.fileContent)> <cfset point=findnocase("value",cfhttp.fileContent)> <cfset saw=mid("#cfhttp.fileContent#",point+7,1)> <cfelse> <cfset saw="0"> </cfif> <cfoutput> returned value is #saw# </cfoutput> </body> </html>
The returned value above should be 9; because, the page sends an 8 to the server being tested. You'll run your code from a remote server of course (after debugging). This example is triggered manually and provides visual feedback so you can see what has happened; you'll want to write your test to be triggered manually, dump its output to a file, and send a signal in some fashion to alert you when a consistent problem occurs.
=Marty=
=============================================================== III. Uppercase The first letter of a word. Jeff Davis Macromedia Certified Cold Fusion Trainer, Developer Fig Leaf Software jdavis@figleaf.com ===============================================================
Regarding Issue 00034's JavaScript Tool Tip, I usually find myself wanting Title case of text input boxes. Looking at Lilly's code, it does ensure that the initial letter is capped... but it leaves all the other letters as is.
Changing the code slightly, I just lower-case all the input, then, same as Lily Wondimu's code, convert the initial letter to upper case. This works with any case input to provide title case of the form contents.
<script> <!-- function textValueToFirstUpper (inpObj) { // brute force everything lower inpObj.value = inpObj.value.toLowerCase(); // now upper the first character inpObj.value = inpObj.value.substr(0, 1).toUpperCase() + inpObj.value.substr(1);
} //--> </script>
Jeff Davis Macromedia Certified Cold Fusion Trainer, Developer Fig Leaf Software ==============
============== IV. process CF Form variables individually Theo den Brinker AIRC/AIR Electronic Publishing theo.denbrinker@air.gov.au
==============
In most instances CF developers will want to process CF Form variables individually such as:
<CFOUTPUT> Your name is : #Form.username# </CFOUTPUT>
There are also situations when you may want to process all the values returned from a form as a group. In this case you can use Form itself as a structure variable. The following code loops over each item in forms and adds the form control name and the form control value to a string variable as a separate line. <!--- create a variable for a new line separator ---> <CFSET CRLF = Chr(13) & Chr(10)>
<!--- create a collection loop to iterate over each key-value pair in the collection. The ITEM "formthing" will hold the key part of each successive key-value pair --->
<CFLOOP Collection=#Form# ITEM="formthing">
<!--- One of the key-value pair created is "FIELDNAME=a list of all the form field names". This we don't need. The submit button value could also be screened out.--->
<CFIF (formthing does not contain "FIELDNAMES") >
<!--- mailstring is updated with a new line containing "KEY : VALUE" for each form control
<CFSET mailstring = mailstring & formthing & " : " & StructFind(Form, formthing) & CRLF> </CFIF> </CFLOOP>
The use that I found is the creation of generic mail-from-form applications which need minimal customization and are fast to deploy. Most of the variable are just collected in a string and which is latter added to the body of CFMAIL. Some key fields such as the user's email address and name can still be dealt with individually.
The Form structure does an output the key=value pairs in alphabetical order. This means that to group form items the form control names should start with the same letter. Such as AA-useraddress, BA-choice1, BB-choice2.
Another use would of the Form structure is to screen and filter each of the income values before dealing with the items individually.
I presume, but have not checked, that URL and CGI are also structures and can be dealt with similarly if required.
Theo den Brinker AIRC/AIR Electronic Publishing
============== Publisher and Creator: Nathan Stanford, admin@cftipsplus.com C.F. Concepts, Inc. http://www.cftipsplus.com ============== Macromedia and ColdFusion are U.S. registered trademarks.
============== Copyright (c) 2000 - 2001 C.F. Concepts, Inc. 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. ===============================================================
============== To unsubscribe: unsubscribe-cftips@nsnd.com
To subscribe: subscribe-cftips@nsnd.com ==============
==^================================================================ EASY UNSUBSCRIBE click here: http://topica.com/u/?aVxjC7.aVG5kO Or send an email To: cftips-unsubscribe@topica.com This email was sent to: cftipsplus@tallylist.com
T O P I C A -- Learn More. Surf Less. Newsletters, Tips and Discussions on Topics You Choose. http://www.topica.com/partner/tag01 ==^================================================================