Completing Construction of a Database Form with HTML
In this conclusion to a thirteen-part series on building database forms with HTML, I will talk about the program that receives the data of the transmitted table at the server. I will show you how to do it using CGI and Perl. Recall that the data is actually HTML Form elements sent from the client’s computer.
Completing Construction of a Database Form with HTML - Brief Explanation of the Web Page Code (Page 6 of 6 )
In the web page code above, you have an HTML Form. The form has the Transmitted table. The value of the display property of the Transmitted table here is “block” and not “none.” I made it this way so that you can see the content on the web page and understand it better. Each control has a name and value. I have made the names to look like IDs. If the names are all unique, then the data should appear at the server, in the order they were at the client.
If you have as a value (already typed) the path and name of an image in a File Input control, the value (image name) may not be sent to the server. This depends on your system. To be sure that the image name (value of the name/value pair) is sent to the server, make sure you link each input text control with an image name, using the corresponding Browse button on the web page. This problem does not occur with the other controls
Brief Explanation of the “receiveData.pl” Program
This is the program that receives the data in the transmitted table at the server. The program that receives the data can save it in a file or in a database at the server. To keep this tutorial simple, the program I wrote saves the data into a new file.
To understand this program, you need basic knowledge of Perl and CGI. You also need basic knowledge of Perl’s CGI class and Perl’s filehandles.
The program begins by creating a new CGI object. It then creates the CGI error object. Next it opens a filehandle to write the data to a file. It creates the file and saves the data into it. It closes the filehandle. It goes on to upload the five files into the cgi-bin directory. Again, I have chosen this directory for simplicity. Finally it checks to see if an error occurred. If there is an error, it sends an error message (web page) to the client’s browser; otherwise it sends a page indicating that the data has been received.
The code essentially deals with writing into a new file and some features of Perl’s CGI class. You do not need to know how the CGI features (methods) operate; you just need to know how to use them. I have written this program as simply as possible. The main aim is to show you how to link the Transmitted table to the server. The interface here is the CGI interface. If you read the code and you do not understand, then learn how to access a file in Perl and how to use Perl’s CGI class.
In the next part of the article, I show you how to produce the web page from the saved file and send to the client’s browser.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.