<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head><title>Registration</title></head> <body> <h1>Registration</h1> <p>To register as a new user, simply fill out this form:</p> <form action="/servlets/doregister.ss" method="post"> <table border="0"> <tr><td align="right"> First & last name: </td> <td><input type="text" name="Name" size="40" value=""/></td></tr> <tr><td align="right"> Email address: </td> <td><input type="text" name="Email" size="40" value="" /></td></tr> <tr><td colspan="2" align="center"> <input type="submit" value=" Submit " /></td></tr> </table> </form> </body> </html>This HTML form has two important bits of information, on the one hand the method used to send the information from the browser to the server, in this case post, which packs the information and sends it to the server once you hit the Submit button. On the other hand, we have the action, in this case an scheme program that will handle the request, process the registration, and return to the client.
cgi.ss, that will help you handle this. Lets review some of the nomenclature, or types, used by this library:
(let* ((b (get-bindings)) (name (extract-binding/single "Name" b)) (email (extract-binding/single "Email" b)))
get-bindings, which returns the whole set of bindings delivered by the client. Note that there is also a
get-bindings/post, and a
get-bindings/get, which only work when the method POST, and GET are used respectively, while
get-bindingsdetermines the kind of method used, and invokes the appropriate procedure.
extract-binding/singlereturns the value associated to the key passed as its first argument in the set of bindings passed as its second argument. The result is either a string representing the value, or a web page with an error, for instance when there was more than one value associated to the key, or the key wasn't found. When there is more than one value, or an unknown number of values, associated to a single key, you should use
extract-bindings, which returns a list with zero, one, or many associations for the key. After getting, and processing the information (validate it, store it in a database, etc.), you will want to return to the client. The
cgi.sslibrary provides one convenient way to do just that:
(generate-html-output "Thank you!" (list (format "Dear ~a, " name) "We have received your information, and this completes the registration process. " "Thank you!"))
cgi.sslibrary, but this should cover the basis. Important: In order to actually be able to run this example (execute the small scheme script above), you need to have a Web server properly configured, the script has to reside in the right place and have the right permissions, and the URI depicted in the action field,
"/servlets/doregister.ss", must point to it. -- FranciscoSolsona - 06 Apr 2004