| #include <stdio.h>
|
| #include <stdlib.h>
|
| #ifdef _WINDOWS
|
| #include <strstrea.h>
|
| #else
|
| #include <strstream.h>
|
| #endif
|
| #include <dcmicro/htmlpp/htmlpp.h>
|
|
|
|
|
| // Test using POST method.
|
| void SubstitutePost( htmlPage& page )
|
| {
|
| // Create a stream object that htmlCgi can accept
|
| strstream url_data ;
|
| url_data << "name1=value1&name2=value2&name3=value3" ;
|
|
|
| // Create the cgi object, setting the necessary member variables
|
| // as if the input were coming from cin (standard input).
|
| htmlCgi server ;
|
| server.Request_Method = "POST" ;
|
| server.Content_Type = "application/x-www-form-urlencoded" ;
|
| server.Initialize( url_data ) ;
|
|
|
| // Output all CGI data to show that html++ has properly decoded the values
|
| String name = server.EnumerateName( "" ) ;
|
| while ( name != "" )
|
| {
|
| page << htmlBold( name )
|
| << " : "
|
| << server( name ) // the value
|
| << htmlBreak() ;
|
|
|
| // loop for next form field
|
| name = server.EnumerateName( name ) ;
|
| }
|
| }
|
|
|
|
|
| // Test using GET method.
|
| void SubstituteGet( htmlPage& page )
|
| {
|
| // Create the cgi object, setting the necessary member variables
|
| // as if the input were coming from the QUERY_STRING environment variable.
|
| htmlCgi server ;
|
| server.Request_Method = "GET" ;
|
| server.Query_String = "name4=value4&name5=value5&name6=value6" ;
|
| server.Initialize() ;
|
|
|
| // Output all CGI data to show that html++ has properly decoded the values
|
| String name = server.EnumerateName( "" ) ;
|
| while ( name != "" )
|
| {
|
| page << htmlBold( name )
|
| << " : "
|
| << server( name ) // the value
|
| << htmlBreak() ;
|
|
|
| // loop for next form field
|
| name = server.EnumerateName( name ) ;
|
| }
|
| }
|
|
|
|
|
| int main( void )
|
| {
|
| htmlCgi server ;
|
| htmlPage page( "html++ form input example" ) ;
|
|
|
| // Test the POST method
|
| SubstitutePost( page ) ;
|
| // Add some space to separate the output
|
| page << htmlBreak() << htmlBreak() ;
|
| // Test the GET method
|
| SubstituteGet( page ) ;
|
|
|
| server << page ;
|
| return 0 ;
|
| }
|
| |