CGI Programming (Part 3)Who is this for What you Need to Have by Now Review of Previous Article We also coded a simple guest book with three fields. If you tried the provided sample, including putting data into the various fields and clicking the Send button, you will see the response from the CGI script when it received your data from the form. It displayed all the elements in the %ENV hash. If you also note the $ENV{CONTENT_LENGTH} field as displayed, you will see that it has a non-zero value. We use this $ENV{CONTENT_LENGTH} to determine if there was in fact something passed to our script or not. If you read the code, the script will display a form if $ENV{CONTENT_LENGTH} is zero. Otherwise, it displays all the contents of the %ENV hash. If you also looked carefully at the contents of the %ENV hash, you do not see the inputs from your form. Reading Input from a Form There are actually two methods to pass data to your CGI script: GET and POST. The difference between the two methods is the way you get the input.
POST Method Since in our sample script, we used the POST method, we have to read the data from STDIN. The sample code will have an additional statement, which are in bold and italicised. |