// Demo of how to use forms and cgi class. // See line that says output.startform and // change the url to match your system! #include #include #include "cgiClass.h" using namespace std; int main(int argc, char** argv) { register int i; cgi output; // Initialize the page, turn on error printing // and set up the header. output.initPage(); output.turnErrorPrintingOn(); output.header("My Title","http://www.cyclismo.org/~black"); // Get form information. // The getFormData method will figure out if the // message uses GET or POST format and acts accordingly. // If argc is one then print out a form, otherwise print // out information obtained by the form. // If there is no argument the program will print // out a survey form. When the information is // posted it will call this same program with an // argument. // // Given an argument the program will get the information // posted from a form and display it using a definition // list. if(argc==1){ // You will have to change this line so that it has // YOUR url in the first argument. output.startForm( "http://www.cyclismo.org/~black/cgi-bin/cgiForm?print", cgi::POST); cout << "Welcome to the test!" << endl; output.lineBreak(); cout << "Please answer a few questions: " << endl; output.rule(); // text field // Example of how to use text and password fields // arguments for text and password go like // this: // // 1) name of field (required) // 2) initial value for field (defaults to nothing) // 3) type of field (defaults to text) // 4) checked initially (ignored) // 5) length of field (default=20) // 6) maximum length (default=40) // cout << "Name: " << endl; output.inputField("Name","Pudd'n Shame", cgi::TEXT,0,20,40); output.lineBreak(); cout << "Password: " << endl; // password field output.inputField("password",NULL, cgi::PASSWORD,0,10,20); // Example of how to use radio buttons. // arguments for radio and checkbox go like // this: // // 1) name of field (required) // 2) value for field (required) // 3) type of field (defaults to text) // 4) checked initially (defaults to no(=0)) // output.lineBreak(); cout << "Lifestyle" << endl; output.lineBreak(); output.startList(cgi::DIRECTORY); output.listItem("Lover"); output.inputField("lifestyle","lover", cgi::RADIO,1); output.listItem("Fighter"); output.inputField("lifestyle","fighter", cgi::RADIO,0); output.endList(cgi::DIRECTORY); // example of how to use checkboxes output.lineBreak(); cout << "Interests" << endl; output.lineBreak(); output.startList(cgi::UNNUMBERED); output.listItem("Baseball"); output.inputField("interests","baseball", cgi::CHECKBOX,0); output.listItem("Labor Disputes"); output.inputField("interests","labor disputes", cgi::CHECKBOX,0); output.listItem("Cable TV"); output.inputField("interests","cable TV", cgi::CHECKBOX,0); output.endList(cgi::UNNUMBERED); // example of how to use a selection field. // Arguments go like this: // 1) Name (required) // 2) Selection to choose from (required) // char** selection // 3) Number of entries in selection // 4) Number of rows to display // 5) Allow for multiple? (1=yes, 0=no) // output.paragraph(); char* locations[] = {"Nepal", "The Outer Banks", "Like somewhere inside, man", "In front of the TV", "On my Harley"}; output.selectionField("Where",locations,5,3,1); output.paragraph(); output.textareaField("essay","the initial value",5,20); // Gotta have a submit and reset button! output.lineBreak(); output.paragraph(); output.submitButton("This be the submit button"); output.lineBreak(); output.resetButton("This be the reset button"); // end the form output.endForm(); } // get form information and display else { // Get form data. // arguments go like this // 1) char **, pointer to data fields (required) // 2) char **, pointer to names of the fileds (required) // 3) int, number of forms returned (required) char **formData=NULL,**formName=NULL; int numForms=0; output.getFormData(formData,formName,numForms); // output the forms using a definition list cout << "Number of forms: " << numForms << endl; output.lineBreak(); if(numForms>0) { output.startDefinitionList(); for(i=0;i