Follow the procedure outlined under 'Connecting to the Server' to capture and print a form field value. Then start writing your validation code as in the example below.
$q
has a function, param( )
, that extracts form data submitted with the POST method. Perl extracts the form data from the HTTP message and puts it into a hash: the intput element's name is the key, the elements data is the value. To extract the data, you pass the element's name as a parameter to the function, and the function will return the value. You can store the value in a variable.
$field = $q->param('text_sent');
This tells the CGI object stored in $q
to get the value associated with the hash key 'text_sent' and put it into the variable $field. If there is no such key, or it has no value, $field will be an empty string.
print $field . "\n";
statement somewhere between the start_html( )
and end_html( )
functions. Note: If the printing statements start_html( )
to end_html( )
were in list format (separated by commata), you must change the comma preceding the print $field . "\n";
to a semicolon and start a new print $q->...