Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!