ColdFusion
  Home arrow ColdFusion arrow Page 3 - Getting Started With ColdFusion Templates ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
COLDFUSION

Getting Started With ColdFusion Templates and Parameters
By: Jackie Kong
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2003-01-02

    Table of Contents:
  • Getting Started With ColdFusion Templates and Parameters
  • Getting Started With ColdFusion Templates
  • Passing Parameters Through the URL
  • Passing Parameters Through Forms
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Getting Started With ColdFusion Templates and Parameters - Passing Parameters Through the URL


    (Page 3 of 5 )

    To create more interactive pages, sometimes you need to pass information (or parameters) from one ColdFusion template to another. There are basically 2 methods to do so:
    • Pass through the URL
    • Pass through a form
    URL Parameters
    To pass a parameter to another ColdFusion template through a URL, you separate the URL from your parameter with a question mark (?). The question mark is followed by a "parameter name = value" pair. This is the standard syntax for passing parameters with any web browser and any web server, and its syntax looks like this:

    <a href="template.cfm?parameter=value">Click here</a>

    If you want to pass more than one parameter, then you need to separate each with the ampersand (&):

    <a href="template.cfm?parameter1=value1&parameter2=value2">Click here</a>

    Let's make a quiz that passes the user's answer through the URL. Enter the following into your editor and save the file as quiz.cfm in the learncf folder:

    <html>
    <body>
    <h1>Today's Quiz</h1>
    What am I learning now?
    <ol>
    <li><a href=quiz_answer.cfm?answer=ASP>ASP</a>
    <li><a href=quiz_answer.cfm?answer=PHP>PHP</a>
    <li><a href=quiz_answer.cfm?answer=ColdFusion>ColdFusion</a>
    <li><a href=quiz_answer.cfm?answer=JSP>JSP</a>
    </ol>
    </body>
    </html>


    You may notice that all the links are pointing to quiz_answer.cfm with the parameters appended to the end of the URL. The parameters differ from one link to another. Now, we need to create the quiz_answer.cfm file, which will handle the answer page. Enter the following code and save it as quiz_answer.cfm in the learncf folder:

    <html>
    <body>
    <h1>Thank you!</h1>
    What am I learning now?<br>
    <cfoutput>
    Your answer was <b>#url.answer#</b>
    </cfoutput>
    </body>
    </html>


    Point your browser to http://localhost/learncf/quiz.cfm and click on an answer. You will see something like this:



    What we have done is passed the value of a parameter from one page to another. You access the value by using #url.answer#, where answer is the parameters name. The url prefix you use here is the scope/type of the parameter.

    How would you go about passing more than one parameter? As I said earlier, it's very easy. You simply separate them with an ampersand (&). The following code will pass the correct answer to the quiz_answer.cfm page by adding &correct_answer=... to the links.

    <html>
    <body>
    <h1>Today's Quiz</h1>
    What am I learning now?
    <ol>
    <li><a href=quiz_answer.cfm?answer=ASP&correct_answer=ColdFusion>ASP</a>
    <li><a href=quiz_answer.cfm?answer=PHP&correct_answer=ColdFusion>PHP</a>
    <li><a href=quiz_answer.cfm?answer=ColdFusion&correct_answer=ColdFusion>ColdFusion</a>
    <li><a href=quiz_answer.cfm?answer=JSP&correct_answer=ColdFusion>JSP</a>
    </ol>
    </body>
    </html>


    The code below is a modified version of quiz_answer.cfm that handles the url.correct_answer parameter as well:

    <html>
    <body>
    <h1>Thank you!</h1>
    What am I learning now?<br>
    <cfoutput>
    <cfif url.answer eq url.correct_answer>
    Congratulations, you answered correctly.
    <cfelse>
    Ops, you are wrong.
    </cfif>
    <br>
    Your answer was <b>#url.answer#</b>
    </cfoutput>
    </body>
    </html>


    The code shown above uses the <cfif> tag to check whether the user clicked on the correct answer. Depending on whether the answer is correct or not, the code will display a corresponding message. <cfif url.answer eq url.correct_answer> effectively evaluates whether url.answer was equal to url.correct_answer. eq is a comparison operator and represents is equal to in ColdFusion:

    More ColdFusion Articles
    More By Jackie Kong


     

    COLDFUSION ARTICLES

    - How to Access a SQL Anywhere Database with C...
    - CFXML: Probing XMLDOM in ColdFusion
    - Creating a Web Service with ColdFusion: the ...
    - CFAjax: What it is and How to Use it
    - Querying SQL 2000 Server from ColdFusion
    - Introduction to ColdFusion Markup Language, ...
    - Introduction to ColdFusion Markup Language
    - Databases and Dreamweaver MX 2004, concluded
    - Databases and Dreamweaver MX 2004
    - Welcome to Coldfusion MX 6.1, concluded
    - Welcome to Coldfusion MX 6.1
    - What You Must Know About ColdFusion Flow-Con...
    - What You Must Know About Operators in ColdFu...
    - Everything You Must Know About ColdFusion Va...
    - My First Application on ColdFusion MX Server






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT