Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // File: Survey.cpp
- // Author:Raul A. Rodriguez M.
- // cs102 Online
- // Date:5/24/2019
- // Description: This program retrieves three form fields and sends the result
- // back to the browser
- #include <iomanip>
- #include <iostream>
- #include <cstring>
- #include <cstdlib>
- #include <string>
- #include "WebApps.h"
- using namespace std;
- WebApps wo;
- const int cnt = wo.get_cnt();
- ////////////functions/////////////
- void build_form () {
- cout << "<html>";
- cout << "<head></head>";
- cout << "<title> Survey shit </title>";
- cout << "<body>";
- cout << "<form action = \"survey.cgi\" method=\"GET\">";
- cout << "</form>";
- cout << "</body>";
- cout << "</html>";
- //simple HTML form to get started
- //use the one from survey_start.txt if you wish
- }
- /**********************************************************************************
- *********************************main begins***************************************
- **********************************************************************************/
- int main()
- {
- void build_form();
- FIELDS *name_value_pairs = wo.create_array(wo.get_cnt());
- string qs(getenv("QUERY_STRING"));
- //string qs("first=fred&last=flint&color=red");
- //cout << "Content-type:text/html\n\n";
- //cout << "debug with qs: " << qs << "<p>" << endl;
- wo.parse(wo.get_qs(), name_value_pairs);
- // debug to show content of name_value_pairs
- /*
- cout << "debug to show content of name_value_pairs array: " << endl << "<br>";
- for (int index = 0; index<cnt; index++) {
- cout << "name: " << name_value_pairs[index].name << " ";
- cout << "value: " << name_value_pairs[index].value << endl << "<br>";
- }
- */
- // Three fields data are retrieved from the param function
- string first = wo.param("first", name_value_pairs, cnt);
- string last = wo.param("last", name_value_pairs, cnt);
- string answer = wo.param("answer", name_value_pairs, cnt);
- // code an HTML page, which includes the three fields
- // received.
- cout << "<html>" << endl;
- cout << "<head>" << endl;
- cout << "<title>Your Bowser Chosen</title>" << endl;
- cout << "</head>" << endl;
- cout << "<body>" << endl;
- cout << "<body background=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRASxpfsyKdmtMvTDuTjm3obSuoKtPseCVBaVi_MpYMIazneNrE/%22%3E\"" << endl;
- cout << "<form action=\"survey.cgi\" method=\"GET\">" << endl;
- cout << "<h1>";
- if(answer=="Google")
- {
- cout << first << " " << last <<", I knew you liked Google!<br>"<< endl;
- cout << "<img src=\"https://i.ytimg.com/vi/-QAFVAoWGuM/maxresdefault.jpg\" alt=\"GoogleMan\">";
- }
- if(answer=="Yahoo")
- {
- cout << first << " " << last << ", Slide and say Yahooo!<br>" << endl;
- cout << "<img src=\"https://i.ytimg.com/vi/5DpspOXs1rM/maxresdefault.jpg\" alt=\"Yahoo\">";
- }
- if(answer=="Bing")
- {
- cout <<"BING BING<br> "<< first << " " << last << ", Someone is at the Door Bell<br>"<< endl;
- cout << "<img src=\"https://digitalreadymarketing.com/wp-content/uploads/2015/05/Bing-question.jpg\" alt=\"bing?\">";
- }
- cout << "</h1>";
- cout << "</form>";
- cout << "</body>";
- cout << "</html>";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement