The cgi class provides methods for sending a simple http header, form processing and reading cookies. Most CGI's or apache modules will need to use methods from this class. Since the groundwork class inherits from the cgi class, if your program uses the groundwork class, then these methods are available through it.
If you don't need to use the features of the groundwork class such as security or multiple skin support, you can write a program that uses the cgi class directly.
A typical CGI will send an http header, read a few form values and write some data to the browser. Here is a simple CGI that reads data posted from an HTML page and writes it back to the browser.
Here is the HTML page that links to the cgi.
<html> <body> Enter your personal information: <form method="post" action="mycgi.cgi"> Name: <input name="name" type="text" value=""><br> Address: <input name="address" type="text" value=""><br> City: <input name="city" type="text" value=""><br> State: <input name="state" type="text" value=""><br> Zip: <input name="zip" type="text" value=""><br> Phone: <input name="phone" type="text" value=""><br> <input name="submit" type="submit" value="Submit"> </form> </body> </html>
Here is the code for the CGI.
#include <groundwork/cgi.h>
#include <groundwork/cgimodule.h>
#include <iostream.h>
MAIN {
cgi *c=new cgi(APISTRUCT);
// send a standard http header
c->sendHeader();
// write some form entries back out to the browser
cout << "The following values were passed in from the previous page:<br>" << endl;
cout << "Name: " << c->formEntry("name") << "<br>" << endl;
cout << "Address: " << c->formEntry("address") << "<br>" << endl;
cout << "City: " << c->formEntry("city") << "<br>" << endl;
cout << "State: " << c->formEntry("state") << "<br>" << endl;
cout << "Zip: " << c->formEntry("zip") << "<br>" << endl;
cout << "Phone: " << c->formEntry("phone") << "<br>" << endl;
delete c;
}
For a more complete explanation of the capabilities of the cgi class, see the documents on form processing and cookies.