CGIScriptDepot.com Your source for CGI Scripts, Tutorials, Remotely Hosted Scripts and more... |
|
CGI Form Processing with Perl
One of the ways that you can interact with your web site visitors is by adding forms in your site. These forms not only serve the purpose of taking the feedback form the already existing customer but can also be used during signing in the new user account, or whatever way you think they can be utilized.
The first step while designing any new form-based script to be included in your site is to create the html form itself. So create a simple form and layout in html, using dreamweaver, frontpage or whatever software you find handy to work on.
Once you are through with the layout, include path you will use for your the CGI script in your page's form action as shown below:
There are two methods you can use to obtain the information from the form, the POST method and the GET method.
Commonly, POST method is used in the submission of forms where you wish to keep the values passed along the form secret or when you have to pass more than 1 KB of data from the form to the CGI Script. The GET method is useful if you're only passing a small amount of data to the CGI Script - less than 1 KB. The GET method stores in the form submitted information with in the URL and therefore you could easily bookmark the submitted form page URL. You cannot do the same with the “post” method that is pages such pages cannot be book-marked.
Depending upon your needs, once the data is submitted from the form, your CGI Script can use it for any purpose. For example, you can get the form information e-mailed to you, store it in a database or even save it in a text file.
Using Form Data in a CGI Script
So, now that you have created a form, how can your CGI Script actually get and use the data from the form? Easy.
If you're feelig daring, you can use your own code to get, parse and store the form data into variables that you can access. That is what I usually do. Here is some example code that puts the form data into an associative array:
If you use the above code, all of your form data will be accessible in the %FORM associative array. To access the data use the following syntax:
where $name is the form field name you want to use and $value is where you want the value to be stored.
You can also use the Perl module CGI.pm to parse Form data. CGI.pm includes code that works similar to the above.
Now that you have access to the data submitted in the form, you can do with it as you wish. For example, send it to someone in email.
Learn More
We maintain a handy list of Perl and CGI Scripting Tutorials that can help get you started creating your own CGI Scripts. Even ifyou are already writing your own CGI Scripts- you might learn a thing or two in our more advanced tutorials.
|
©2003-2005 Assorted Internet Ventures LLC |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |