| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| <head> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <title>Variable Access</title> |
| <link rel="stylesheet" href="../rivet.css" /> |
| </head> |
| <body> |
| <!--p align="center"></p --> |
| <!-- ? |
| parray rivetweb::menus_a |
| ? --> |
| <div id="bigcontainer"> |
| <div id="pageheadline"> |
| <div class="decoration"><img src="../picts/Rivetlogo_smaller.png" alt="Apache Rivet" /></div> |
| <div class="headline">Variable Access</div> |
| </div> |
| <div id="pagecontents"> |
| <div class="navbar navleft"><div class="staticmenu" id="main"> |
| <div class="menuheader">Rivet</div> |
| <div class="itemcontainer"> |
| <span class="navitem"> |
| <a href="../index.html" class="menuitem">Rivet Homepage</a> |
| </span> |
| <span class="navitem"> |
| <a href="http://tcl.apache.org/">Apache Tcl Home</a> |
| </span> |
| <span class="navitem"> |
| <a href="http://www.tcl.tk/">The Tcl Language</a> |
| </span> |
| <span class="navitem"> |
| <a href="download.html" class="menuitem">Getting Rivet</a> |
| </span> |
| <span class="navitem"> |
| <a href="http://tcl.apache.org/rivet/manual/">Documentation</a> |
| </span> |
| <span class="navitem"> |
| <a href="hello_world.html" class="menuitem">Examples</a> |
| </span> |
| <span class="navitem"> |
| <a href="about.html" class="menuitem">About Us - Contact</a> |
| </span> |
| </div> |
| </div> |
| <div class="staticmenu" id="examples"> |
| <div class="menuheader">Examples</div> |
| <div class="itemcontainer"> |
| <span class="navitem"> |
| <a href="hello_world.html" class="menuitem">Hello world!</a> |
| </span> |
| <span class="navitem"> |
| <a href="shaded_table.html" class="menuitem">A shaded table</a> |
| </span> |
| <span class="navitem"> |
| <a href="var_access.html" class="menuitem">Variable Access</a> |
| </span> |
| <span class="navitem"> |
| <a href="file_upload.html" class="menuitem">File Upload</a> |
| </span> |
| <span class="navitem"> |
| <a href="file_download.html" class="menuitem">File Download</a> |
| </span> |
| <span class="navitem"> |
| <a href="ajax.html" class="menuitem">XML and Ajax</a> |
| </span> |
| </div> |
| </div> |
| |
| </div> |
| <div class="navbar navright"></div> |
| <div id="content"> |
| <div class="contentheadline"></div> |
| <div><div class="example"> |
| <p class="title"> |
| <b>Example 3. Variable Access</b> |
| </p> |
| <div class="example-contents"> |
| <p>Here, we demonstrate how to access variables set by GET or POST operations.</p> |
| <p>Given an HTML form like the following:</p> |
| <pre class="programlisting"> |
| <form action="vars.rvt"> |
| <table> |
| <tbody> |
| <tr> |
| <td><b>Title:</b></td> |
| <td><input name="title"></td> |
| </tr> |
| <tr> |
| <td><b>Salary:</b></td> |
| <td><input name="salary"></td> |
| </tr> |
| <tr> |
| <td><b>Boss:</b></td> |
| <td><input name="boss"></td></tr> |
| <tr> |
| <td><b>Skills:</b></td> |
| <td> |
| <select name="skills" multiple="multiple"> |
| <option>c</option> |
| <option>java</option> |
| <option>Tcl</option> |
| <option>Perl</option> |
| </select> |
| </td> |
| </tr> |
| <tr> |
| <td><input type="submit"></td> |
| </tr> |
| </tbody> |
| </table> |
| </form> |
| |
| </pre> |
| <p>We can use this Rivet script to get the variable values:</p> |
| <pre class="programlisting"><? |
| set errlist {} |
| if { [var exists title] } { |
| set title [var get title] |
| } else { |
| set errlist "You need to enter a title" |
| } |
| |
| if { [var exists salary] } { |
| set salary [var get salary] |
| if { ! [string is digit $salary] } { |
| lappend errlist "Salary must be a number" |
| } |
| } else { |
| lappend errlist "You need to enter a salary" |
| } |
| |
| if { [var exists boss] } { |
| set boss [var get boss] |
| } else { |
| set boss "Mr. Burns" |
| } |
| |
| if { [var exists skills] } { |
| set skills [var list skills] |
| } else { |
| lappend errlist "You need to enter some skills" |
| } |
| |
| if { [llength $errlist] != 0 } { |
| foreach err $errlist { |
| puts "<b> $err </b>" |
| } |
| } else { |
| puts "Thanks for the information!" |
| ?> |
| <table> |
| <tbody> |
| <tr> |
| <td><b>Title:</b></td> |
| <td><? puts $title ?></td> |
| </tr> |
| <tr> |
| <td><b>Boss:</b></td> |
| <td><? puts $boss ?></td> |
| </tr> |
| <tr> |
| <td><b>Salary:</b></td> |
| <td><? puts $salary ?></td> |
| </tr> |
| <tr> |
| <td><b>Skills:</b></td> |
| <td><? puts $skills ?></td> |
| </tr> |
| </tbody> |
| </table> |
| <? |
| } |
| ?> |
| </pre> |
| <p>The first statement checks to make sure that the boss variable has been passed to the script, |
| and then does something with that information. If it's not present, an error is added to the list of errors.</p> |
| <p>In the second block of code, the variable salary is fetched, with one more error check - because it's a |
| number, it needs to be composed of digits.</p> |
| <p>The boss variable isn't required to have been sent - we set it to "Mr. Burns" if it isn't among the |
| information we received.</p> |
| <p>The last bit of variable handing code is a bit trickier. Because skills is a listbox, and can |
| potentially have multiple values, we opt to receive them as a list, so that at some point, |
| we could iterate over them.</p> |
| <p>The script then checks to make sure that errlist is empty and outputting a thankyou message. |
| If errlist is not empty, the list of errors it contains is printed.</p> |
| </div> |
| </div> |
| |
| |
| </div> |
| |
| </div> |
| <div class="clearfloats"></div> |
| <!--div class="leftaligned">:</div> |
| <div class="rightaligned">:</div--> |
| <div> |
| <table align="center" width="100%"> |
| <tr> |
| <td align="left"> |
| <a href="http://www.apache.org/"> |
| <img src="../picts/apache_pb.gif" alt="Powered by Apache" border="0" width="259" height="32"></a> |
| |
| </td> |
| <td align="right"> |
| <a href="http://www.tcl.tk/"> |
| <img src="../picts/tclp.gif" alt="Powered by Tcl" border="0" width="42" height="64"></a> |
| </td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| </div> |
| </body> |
| </html> |