Lightweight, Component-based, and Database-oriented Web Application Framework

About | Overview | Documentation


Documentation > Modules and APIs > Data_HTML_Map




The core module used to render CGI parameters values inside the view template before CGI_HTML_Map module was available. After the availability of CGI_HTML_Map module, Data_HTML_Map module was specifically used to render CGI parameters' values which represent the values of database table fields involved in the insert/update/delete operations. It's actually used to support dynamic and interactive view features for database table items insert/update/delete operations.

This module has been used inside the following Webman-framework's component type modules: webman_db_item_insert, webman_db_item_update, webman_db_item_delete, webman_db_item_insert_multirows, webman_db_item_update_multirows, and webman_db_item_delete_multirows.


1. View Template

Below is the most generic example of view template contains HTML-form input elements represents database table field names to be used in conjunction with Data_HTML_Map module. The paired template tags <!-- start_datahtml_ name=form_db_field //--> and <!-- end_datahtml_ //--> are used to mark input elements involved, which also become the content parts to DATAHTML template-element (lines 06-11). The input elements which will be later passed as CGI parameters are named in the form of $db_field_name_1, ..., till $db_field_name_n to adhere the naming convention requirements imposed by other core module (HTML_DB_Map) that is responsible for the real database operations.

Note that in the below view template, $db_field_name_1 and $db_field_name_1_ are two different things. The former is the input element name to be passed as one of the CGI parameters as explained above. The later is template-element's word pattern, treated by Data_HTML_Map module as a place-holder to render the coresspond CGI parameter value.

  1 <html>                                                                                      
  2 <body>                                                                                      
  3 <!-- start_view_ //-->                                                                      
  4 <form method="POST" action="./index.cgi">a                                                  
  5   <!-- start_datahtml_ name=form_db_field //-->                                             
  6     field_caption_1_ : <input name="$db_field_name_1" type="text" value="$db_field_name_1_">
  7     <p />                                                                                   
  8     ...                                                                                     
  9     ...                                                                                     
 10     field_caption_n_ : <input name="$db_field_name_n" type="text" value="$db_field_name_n_">
 11     <p />                                                                                   
 12   <!-- end_datahtml_ //-->                                                                  
 14   <input name="button_submit" type="submit" id="button_submit" value="Proceed"/>            
 15   <input name="button_submit" type="submit" id="button_submit" value="Cancel"/>             
 16 </form>                                                                                     
 17 <!-- end_view_ //-->                                                                        
 18 </body>                                                                                     
 19 </html>                                                                                     

In the context of Webman-framework's component implementation, the above DATAHTML template-element will be passed to and processed inside process_DATAHTML hook function (see section 4).

2. Instantiation and Basic Parameter Setting

The passed argument $cgi is other Webman-framework core module instance. The $cgi is an instance of GMM_CGI module.

my $data_HTML = new Data_HTML_Map;

### Option to escape basic HTML's tag characters ('&', '<', '>', '"') to 
### ("&amp;", "&lt;", "&gt;", "&quot;") respectively. The argument $num 
### can be set to 0 or 1.

3. Processing Template Element Content

my $content = $data_HTML->get_HTML_Code;

4. Implementation Inside Hook Function

sub process_DATAHTML { 
    my $this = shift @_;
    my $te = shift @_;

    my $cgi = $this->get_CGI;
    my $dbu = $this->get_DBU;
    my $db_conn = $this->get_DB_Conn;
    my $te_content = $te->get_Content;
    my $te_type_num = $te->get_Type_Num;
    my $te_type_name = $te->get_Name;
    ### Start process template element content.
    if ($te_type_name eq "form_db_field") {
        my $data_HTML = new Data_HTML_Map;

        ### Option to escape basic HTML's tag characters ('&', '<', '>', '"') to 
        ### ("&amp;", "&lt;", "&gt;", "&quot;") respectively. The argument $num 
        ### can be set to 0 or 1.

        my $content = $data_HTML->get_HTML_Code;