| the complete webmaster | ||||
| tutorials | reviews | reference | ||
|
Introduction to CGI ScriptsTo get started with CGI, it's useful to have a few good examples that demonstrate the principles of accepting input from an HTML form, processing and then storing the data. This week's article and the ones that follow will do just that. This is part of a series of articles discussing CGI processing. Part I introduces the basic HTML elements that are used to create a form. Part II discusses how those elements are transferred to the web server and processed by a CGI program. Part III discusses the difference between POST and GET. Finally, Part IV shows how data collected by a CGI program can be stored on the server. HTML Form ElementsIn general, CGI forms have two separate parts. First, an HTML file containing the form's elements (buttons, check boxes, input fields, etc) is displayed to the user. Then, it is submitted to a server where a CGI script processes it.As you know, HTML files are made of tags, such as <TITLE>, <H1>, <BR>, etc. Likewise, there are specific tags that are used in forms. A form is started with the <FORM> tag, then come the form elements, and it ends with the </FORM> tag. One HTML file may have many separate forms, but, in practice it's usually best to have just one. In an HTML file, start the form with the following tag: <FORM METHOD="get" ACTION="/cgi-bin/script.pl"> The METHOD can be either get or post. The getmethod sends the form's data back in the URL and on the server, the environment variable QUERY_STRING will be set to the contents. The post method sends the data back separately, and the script reads it from standard input (STDIN). The ACTION specifies the URL of the CGI program that will process the data. The Form Tags |
| write for us | about us | advertise |
Copyright 1997, 1998 A Big Lime. All rights reserved.