Chapter 6. The CGI Module
Introduction to GET and POST
The CGI Module, CGI.pm
Handling Form Errors
Handling Fatal Errors
Handling Form Input
To see how the CGI module helps you handle form input, let's look at another simple example.
Here's a form. Have a look at it, and look at its source in the source viewing window if you want to. It's just a plain HTML file with a form in it. The form's action is set to POST.
Try pushing the "Add Me!" and "Don't Add Me" buttons to see what happens.
the script that gets called as the action of the form.
creates a web page on the fly for you.
We can even serve up a page, with your name put into it. Try this form instead, and you'll see your details come right back into this page.
Here's the script to do this
Pretty straightforward now that you know how to edit files on the fly. Once you get the data from the user, you can do anything you like with it; you can use it to customize content, or stash it in a database somewhere.
The next topic will discuss how to protect yourself against form errors so you can make the user fill in fields when they are not filled in properly.
Email me your comments!