Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code to capture information from an html form using string processing: the name/value pairs from the URL will be parsed from QUERY_STRING into an array

Code to capture information from an html form using string processing:

the name/value pairs from the URL will be parsed from QUERY_STRING into an array of

structs, which will hold the name/value pairs.

// Prints all items in a string that are separated by a common delimiter.

void parse(string parseString, string delimiter) {

string value;

int startPos = 0, pos = parseString.find(delimiter);

while (pos != string::npos) {

value = parseString.substr(startPos, pos - startPos);

cout << value << endl;

startPos = pos + delimiter.length();

pos = parseString.find(delimiter, startPos);

}

value = parseString.substr(startPos, parseString.length() - startPos);

cout << value << endl;

// Example call:

parse("this::is::a::test", "::");

Note: this function has been modified to work with our web form application (below).

Copy and paste into your own version of retrieve_form.cpp from the following

start file:

http://toolkit.cs.ohlone.edu/~jond/cs102/retrieve_form_start_cpp.txt

This start file already contains a struct for the name/value pairs, an array,

and two functions, one of which (parse()) is almost already complete.

Complete the following:

Add code to the parse function, which will populate the name_value_pairs array.

Complete the function 'param()' based on the prototype, calls, and

definition, which are already in place.

The function 'param()'s job is to match the field name passed in its parameter

to the corresponding array struct element. Once the appropriate structure is

matched, the value for that field can be returned.

Return "" (an empty string) if the element for that name is not found in the

array - (no match from the html form).

Use your own fields by modifying the web_form.html code appropriately (first, last,

and color are not required, just examples) .

As a final touch, return the data received back to the browser in some

creative way. For example the color chosen by the user could be used to change

the background color of the page. Again, this is only an example - be creative.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

Students also viewed these Databases questions