- slide 1 of 3
A Little Background
If you have experience with building web sites, you will know that you can use any HTML editor or a mixture of other tools to create web pages. To have a website online is simply a matter of uploading the page to the right place on the web server and voila! Your website is up and working. However when you begin working with HTML forms, things won’t be that simple anymore. Sure, you can design your forms using any HTML editor but you can’t get the form to do anything simply with HTML. You need something extra such as CGI scripts for forms.
You will also find that after designing a fantastic looking form with your HTML editor and uploading it to your website, you fill out the form inputs and click the submit button…..and nothing happens! In reality for you to get a form working it simply won’t suffice to just design the form itself in HTML, you also have to create a form processor script and point the form to it. The form processor is called a CGI script for forms and CGI simply stands for Common Gateway Interface. It runs on the web server and takes the data entered in the web form by the user and processes it.
- slide 2 of 3
CGI Script and Forms
What the CGI script does with the web form basically depends on the complexity of the form. In the case of a simple contact form, the CGI script for forms processor may do nothing but send the information entered in the form to an email address. (Usually contact forms are used to hide the recipient's actual email address, as exposing it on the website may result in tons of spam). But for a more advanced application, the CGI script form processor would be a very complex program which ties in with the database and carries out an assortment of functions.
CGI scripts are never a part of the HTML but rather separate programs that are installed on the web server. The location of the form processor is spelt out in the HTML codes in this manner:
The above code shows where the CGI script is located and must be installed and set up on your web server.
After designing a web form with any HTML editor to let our browser recognize where to forward the content of the form we need to add these properties:
<form>tag: action = address, method = post or method = get
The address is the location of the CGI script for forms on the web server that the content should be sent to, while the post and get methods are simply other ways of submitting to the CGI form script.
- slide 3 of 3
CGI Script for Forms Example
Let’s look at a typical form tag with action and method specified as well as the location of the CGI script specified.
Where: = http://www.myhostings.com/cgi-bin/formail.cgi%20is%20the%20location%20of%20the%20CGI%20script%20located%20on%20the%20web%20server.%20And%20form%20method%20= “post” as shown in the screenshot above.
Finally from the foregoing we have learnt that web forms need a CGI script for forms to work otherwise we may be left with an aesthetically well designed form but without functionality.