ColdFusion
  Home arrow ColdFusion arrow Page 4 - 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 Forms


    (Page 4 of 5 )

    On the last page we learnt how to pass parameters through the URL. This is an easy and method and is most suitable for passing small amount of data. However, one problem with this method is that the parameters you pass are visible in the address bar of the browser (for instance, when quiz_answer.cfm is displayed). A solution for this is to pass the parameters through a form.

    Pass Through a Form
    Passing parameters through a form involves basic HTML form elements such as <form>, <input type=text>, <input type=hidden> and <input type=radio>.

    Now, let's convert our quiz to pass variables through a form instead of the URL. This basically involves assigning an <input type=radio> element to each quiz answer. Enter the following code into your text editor and save the file as quiz_form.cfm.

    <html>
    <body>
    <h1>Today's Quiz</h1>
    What am I learning now?
    <form method="post" action="quiz_form_answer.cfm">
    <ol>
    <li><input type=radio name=answer value=ASP> ASP
    <li><input type=radio name=answer value=PHP> PHP
    <li><input type=radio name=answer value=ColdFusion> ColdFusion
    <li><input type=radio name=answer value=JSP> JSP
    </ol>
    <input type=hidden name=correct_answer value=ColdFusion>
    <input type=submit>
    </form>
    </body>
    </html>


    You need to create another page to check the answer of the question. Enter the following code and save the file as quiz_form_answer.cfm:

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


    In the quiz_form_answer.cfm file, you may notice that we used a <cfif> statement to check the correctness of the answer. This statement compares form.answer with form.correct_answer to see if they are the same. If they are the same then the user has answered correctly; otherwise he is wrong. As in our URL example, eq in the <cfif> statement is a comparison operator for equality. There are other equality operators, and they are listed below:
    • eq: equal
    • lt: less than
    • gt: greater than
    • lte: less than or equal
    • gte: greater than or equal
    • neq: not equal to
    Notice that values of radio buttons and correct_answer (hidden input field) are accessed with #form.xxx#. You can safely leave "form." out, but putting it in will make the page process slightly faster because you are telling ColdFusion that the parameters/variables belong to the form scope of the page explicitly.

    Lastly, we need to test our new form-driven questionnaire. To test it, point your browser to http://localhost/learncf/quiz_form.cfm. You should see something like this:

    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 6 hosted by Hostway
    Stay green...Green IT