Site hosted by Angelfire.com: Build your free website today!

.

Howto Create a HTML form and read it into a CGI script

To test CGI scripts you need to install a local web server.
PROGRAMMING BY AMATEURS, FOR AMATEURS!
Under "Installing Apache web server" choose you OS's install.

New that Apache 2 is installed and configured. Let test it.
In you web browser's address bar type 127.0.0.1 (Loop back address).
It did not work??
Lets start the web server.
If the httpd.exe console window is open. Close it and then click on the httpd.exe shortcut.
In web browser type 127.0.0.1
You'll see "It works!" and a Send button. Press it.
If the CGI script executed. You will see "Hello world".
The "Hello world" CGI test script is in
https://russellman128.angelfire.com/ApacheWindowsInstall.htm
All this is necessary because you need to know that the web server is setup right.

Lets create an HTML form and name it AddressForm.html.

Copy this and save as AddressForm.html. And copy it to C:\Apache24\htdocs.
Create a html link to it in the index.html file.
By adding this line to the index.html file.

New you have a like to AddressForm.html in your index.html file.
Click on it.
If an error saying "Not Found".
Look at the AddressForm.html and see if your text editor add a ".txt" to the end of it.
If so remove the .txt .

Wright a CGI script to Receive, transcribe, And display the form's input.
Open Codeblocks and create a console app called AddressBook.
Copy the code below into the main.cpp file (overwriting it).
Compile it.
Rename the AddressBook.exe to AddressBook.cgi and copy it to the C:\Apache24\cgi-bin directory.

Copy this to the bottom of the index.html file.

So what have we done so far.
Created a link to a HTML form.
How to have 2 forms on the same page.
Code to receive data, transcribe data, send data.

Sending and receiving data: POST and GET.
We need to know something about how CGI script's send the data.
There is 2 method. POST and GET.
The basic difference is:
GET append the string to the end of the address, in plain text.
And has a limit of 256 charters. It is used by most search engines.
Post limit is the amount of memory you have avoidable. And send it through the environment variable.
When receiving data by POST or GET. Always check the length of the data.
You do not wont someone to send you the ecclesiastical britannica and over loading the server. (DOS attack).
We are using POST.
If you use GET and sent the data. The data would look like this.
http://localhost/cgi-bin/AddressBook.cgi?FName=John&LName=Doe&Age=101&FNum=555-121-1212
POST data look like this.
FName=John&LName=Doe&Age=101&FNum=555-121-1212
The first thing we need to do to the data revived is transcribes it.


Basely all this code does replace one charter with a charter or space.
With one exception '%' line and it does 2 charters.

Add data to the Xbase 3 file