Hidden Fields
[Previous] [Main] [Next]

 
The htmlInputHidden class is used to place hidden field data within forms. Hidden fields are not displayed by browsers but are transmitted with other name/value pairs when the form is submitted to a server. Hidden fields are commonly used to embed control data, or to pass state information between pages.  
 
Note that though hidden fields are not displayed by browsers, they should not be considered secure unless explicitly encrypted. Hidden fields may be viewed by users if they view the HTML source of a page.  
 
htmlInputHidden objects are used the same as most other form-related input fields. Two versions of the constructor are available, one without any arguments and the other accepting a name and value pair.  
 
To use hidden fields in a form, construct an htmlInputHidden object and add it to a form using the << operator or the Add() method:  
 
#include <stdio.h>  
#include <stdlib.h>  
#include <dcmicro/htmlpp/htmlpp.h>  
 
int main( void )  
{  
   htmlCgi   server ;  
   htmlPage  page ;  
   htmlForm  form( "/cgi-bin/yourapp" ) ;  
 
   form << htmlInputHidden( "customerid""1234" )  
        << htmlInputSubmit() ;  
   page << form ;  
 
   server << page ;  
   return 0 ;  
}  
 
The above code doesn't do much, but it does illustrate the mechanics of adding a hidden field to a form. When rendered by a browser, the name/value pair describing the customer ID won't be displayed but will be sent to the server when the submit button is pressed.  
 
When passing form data from one page to another, it's often desirable to include all fields from previous pages in subsequent pages. For forms with more than a few fields, this process would normally be extremely cumbersome -- using the htmlCgi::AsHidden() method makes it easy.  
 
The htmlCgi class provides an interface to retrieve name/value pairs from forms by name. htmlCgi::AsHidden() accepts a reference to a form as it's only argument, and automatically creates and inserts htmlInputHidden objects for each name/value pair in the CGI variable list into the form. Using this technique, all an application needs to do to assemble a full list of form fields for all pages is to continue calling htmlCgi::AsHidden() for each page. When the last page is submitted, the application can access the data from all pages as if they came from a single page!  
 


©1998 DC Micro Development. All rights reserved.
No portion of this document may be c opied or reproduced without expressed written consent.
html++ is a trademark of DC Micro Development.