|
![]() |
|
![]() ![]() | Guides & Standards - Forms - cgifileThe cgifile program, located on the main Web server, gives you the ability to append information to a file and ultimately import the results into databases. This utility will only work for Web files on the main Web server (www.wright.edu). Refer to http://www.wright.edu/web/resources/formcgifile.html to see a working example of a form using the cgifile program. Step 1: Create Your cgifile Template and incoming.txt File
Before you may receive any entries to later be imported, you must first create a text file that contains the guidelines regarding the user's submissions. You must define what information you want to receive, and also the order in which you would like it to be listed. [firstname]|[lastname]|[gender]|[status]|[class]|[housing]|[comments] The blank line is required so that each submission will be written on a new line, and make importing into a database possible. Also, instead of using commas to distinguish different fields, you may use other special characters (e.g. - $, %, *). In naming the template, it is helpful to use the same filename as the form - with a .txt extension. Further, you must create an empty text file that will house the results submitted by the user. Each individual entry will be created on a new line and will be appended to the data file. This empty text file must be named "incoming.txt" when using cgifile and must be placed in the same directory as the template text file. After you have created the incoming.txt file and placed it on the main Web server, e-mail the WSU Web Team (webmaster@wright.edu) so that we can set the correct permissions for the file. Tell us your name, username, and the web address of the incoming.txt file. Note: Save the files as ASCII text. Now you are ready to create the HTML form. Step 2: Create the FormExample: <form action="http://www.wright.edu/cgibin/cgifile/web/resource/cgifile.txt" method="post"> <p> <p> <input type="radio" name="gender"
value="Male"> Male <p> <select name="class" size="3"> <p> <select name="housing"> <p> <p> </form> Note that the name attribute of each <input> tag corresponds to what you previously put in each square bracket in the template. These must match exactly. Only use lowercase letters and no spaces or special characters (e.g. - !, &, *). The action attribute of the <form> tag is split into two parts. If you are using a form in your personal UNIX directory, the form action line would be as follows: <form method="post" action="http://www.wright.edu/cgibin/cgifile/~e-mail.name/sample_form.txt"> Notice that the first part of the pathname refers to the cgifile program. The second part refers to the location of your e-mail template relative to the Web server (www.wright.edu). If you are using a form on a departmental Web site, the second part
of the action
line would be the server relative path to your text template file.
Once the user submits the form, he/she will receive a confirmation of what was submitted. Cgifile will show the user the line of information that was appended to "incoming.txt". The following information was written: John | Doe | Male | Student | First-year student | Forest Park | Hello world! cgiemail 1.6 This looks very bland, but is an easy way of letting the user know that the information was submitted successfully. If you don't want the user to see this simple "success" page, you can place an additional line into your form and make a separate Web page load once the user has submitted his/her information. To do this add the following in your HTML form, somewhere between the beginning and end of the form. <input type="hidden" name="success" value="http://www.wright.edu/~yourname/success.html"> The URL in "value" can point to any Web page you prefer. Test the sample form to see a sample "success page". Step 3: Post Your HTML Form and Text Template to the Web ServerAfter you post your HTML form and text template to the Web server, test the form by filling out and submitting it a few times. Try to vary your responses and attempt to anticipate any mistakes your intended audience may make. Further information on the cgifile program is located online at http://www.sfsu.edu/training/cgifile/cgifile.htm Step 4: Importing Results into a MS Access DatabaseWhen you are ready to take the data obtained from your form and sort the results, you must first download the "incoming.txt" file. The following instructions will explain how to take your form data and create a simple database in Microsoft Access.
|
|