Share via


Naming Parameters with ON_PARSE_COMMAND_PARAMS

OverviewHow Do I

This part of the example shows how to use the ON_PARSE_COMMAND_PARAMS macro to name parameters. Named parameters can appear in any order, as long as they precede all optional ones. They are useful in writing a function with a variable number of parameters for responding to a submit button on an HTML form. For example, you can create an HTML form to collect name, address, or additional information. When the user clicks the submit button on the form, a URL containing the information the user entered is passed to the server. Your parse maps can specify default values for optional fields. For information about HTML tags that specify how a form’s content is sent to the server, see Internet First Steps: HTML.

The RegisterUser function takes three parameters: First, Middle, and Last:

BEGIN_PARSE_MAP( CServerDerived, CHttpServer )
ON_PARSE_COMMAND( RegisterUser, CServerDerived, ITS_PSTR ITS_PSTR ITS_PSTR )
ON_PARSE_COMMAND_PARAMS("First Middle Last")
END_PARSE_MAP( CServerDerived )

The corresponding command handler is written like this:

CServerDerived::RegisterUser( CHttpServerContext* pctxt, LPCTSTR pstrFirst, LPCTSTR pstrMiddle, LPCTSTR pstrLast )
{
   // do processing here!
}

For example, if the client uses a fill-in form with METHOD=GET, ACTION="http://mooseboy/survey/survey.dll?RegisterUser" and three text boxes named "First", "Middle", and "Last" to invoke RegisterUser, and the user enters the values "Richard", "M.", and "Jones", the URL will be formatted as follows:

http://mooseboy/survey/survey.dll?RegisterUser?First=Richard&Middle=M%2E&Last=Jones

The parse map looks at eachname=valuepair and assigns the value accordingly — all three parameters toRegisterUserwill correctly resolve to "Richard", "M.", and "Jones", respectively.

What do you want to know more about?