Webman-framework

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

About | Overview | Documentation

 

Documentation > Tutorial > 6.2 Guestbook entry page: Entry testing and module customization

6.2 Guestbook entry page: Entry testing and module customization

 

In the previous sub-section (6.1), resources for guestbook entry page have been prepared automatically via the use of code generator script provided by the framework. To test the result, go back to browser's window/tab for mygb application, click the "Sign Guestbook" main link, and enter the required input fields as follows.

 

Click the "Proceed" button and the entry form remains displayed with blank field error for "Entry" form field is highlighted.

 

Do remember that in mygb_entry table design (section 5) the entry field is set as a not null field. Based on this information the code generator script automatically set the required parameter setting for "mygb_entry_std_insert" DYNAMIC_MODULE type reference so the module will not proceed with insert operation and display the error when the "Entry" form field is left blank.

Avoid this error by entering the "Entry" form field with the text entry as follows.

 

Click the "Proceed" button again and the confirmation page for insert operation should be displayed as below.

 

To continue the operation click the "Confirm" button and the initial blank form fields for insert operation will be displayed back by the application.

Let's make the application more interesting by changing its behaviour so each time after users submitted their entries the application will redirect them to the "List Entry" node page. Also revise the database table design in section 5 where the application is required to programmatically set the default value of nickname field to "Anonymous" if it's left blank by the user. All these will require some code modifications inside the module that handle the insert operation. Prior to the modifications of the module it's important to really understand how the target module was constructed previoulsy. Below is the inheritance hierarchy relationships of the target module (mygb_entry_std_insert.pm).

                     CGI_Component.pm
                            
                  webman_CGI_component.pm
                            
                  webman_db_item_insert.pm
                            
                  mygb_entry_std_insert.pm

 

To get detailed information how mygb_entry_std_insert.pm module could be customized, read the documentation on all parent-type modules involved in the above module's parent-child hierarchy relationships (CGI_Component, webman_CGI_component, and webman_db_item_insert). For each parent-type module's documentation, give the concentration on "Child Module for Customization" sub-section. The next paragraph shows how mygb_entry_std_insert.pm module is customized following the specifications inherited from the parent-type modules modules involved in the hierarchy.

Open mygb_entry_std_insert.pm module file and modify its run_Task function by adding new lines of code as shown follows.

  1 sub run_Task {                                                  
  2     my $this = shift @_;                                        
  3                                                                 
  4     my $cgi = $this->get_CGI;                                   
  5     my $dbu = $this->get_DBU;                                   
  6     my $db_conn = $this->get_DB_Conn;                           
  7                                                                 
  8     my $login_name = $this->get_User_Login;                     
  9     my @groups = $this->get_User_Groups;                        
 10                                                                 
 11     my $match_group = $this->match_Group($group_name_, @groups);
 12                                                                 
 13     if ($this->confirm_Phase) {                                 
 14         if ($cgi->param("\$db_nickname") eq "") {               
 15             $cgi->push_Param("\$db_nickname", "Anonymous");     
 16         }                                                       
 17                                                                 
 18     } elsif($this->last_Phase) {                                
 19         $cgi->redirect_Page("index.cgi?link_id=8");             
 20     }                                                           
 21                                                                 
 22     $this->SUPER::run_Task();                                   
 23 }                                                               

Inside the above run_Task function, line 13 through line 20 are the new lines of code added for the purpose of mygb_entry_std_insert.pm module customizations. Generally the new added lines handle module's multi-phase page interaction that inherited from webman_db_item_insert base module.

At lines 14 to 16, that is at the confirmation phase, the module will by default set the CGI parameter named $db_nickname to "Anonymous" if it has no value assigned to it. This particular CGI parameter represents the nickname field inside the mygb_entry table. Read the documentation on webman_db_item_insert base module (sub-section 1.1) for more detailed descriptions on how table field names are represented inside the form. Redirection to "List Entry" node page is simply done at line 19 when the module has reach its last phase. Please note that the "List Entry" node has the link id "8".

The $cgi reference-type variable inside the run_Task function above is actually a reference to an instance of "GMM_CGI" module, which is one of framework's core module. Do read the documentation on GMM_CGI core module to get information how this type of instance could be used inside the application.

Save mygb_entry_std_insert.pm module and test "Sign Guestbook" form page with entries as follows.

 

Click the "Proceed" button and the customizations should able to automatically assign the "Nickname" field with the value of "Anonymous" as shown below.

 

Continue the insert operation by clicking the "Confirm" button and this time the customizations should able to redirect the browser to the "List Entry" node's page.

Since the list page is still not implemented, there is no other way to check if the entries have been correctly saved into the table other than directly make a query to the database itself. Using the MySQL command-line interactive client tool, it can be done as shown below.