3.2. CGI Scripts

Every module contains at least one CGI script called index.cgi. This is the main page of the module and will be displayed when the module is chosen from a menu item. Additional scripts can be created if necessary to break the module's functionality onto separate pages and should be named based on their task.

3.2.1. Display CGI Scripts

Normal display CGIs should use the WebTool::UI::Std class. This will ensure they contain the proper headers, footers and menus.

use WebTool::UI::Std;
my $page = new WebTool::UI::Std;

3.2.2. Popup CGI Scripts

Popup CGIs are generally used for displaying information or allowing input of small forms. They should use the WebTool::UI::Popup class, which uses different headers and footers and does not contain a menu. Use the popup_link or popup_button methods of your page object on the launching page to create the popup windows, see Section 2.3.1 for more information.

use WebTool::UI::Popup;
my $page = new WebTool::UI::Popup;

3.2.3. Action CGI Scripts

These are scripts whose purpose is to perform an action rather than display a page. Your form pages should post to an action page to perform the required task, which will then redirect back to a normal page using either a close_popup or a redirect function. The form script generally would be named with an edit_ or create_ prefix, while the associated action script would be named with a do_edit_ or do_create_ prefix.

A typical action script uses the process_form function to gather the HTTP post variables from the previous page, validates the input, calling the err function if any input is deemed invalid, performs the required task, then redirects or closes the popup.

use WebTool::UI::Popup;
my $page = new WebTool::UI::Popup;
my %in = WebTool::UI::process_form();

if (!$in{'required_field'}) { $page->err("The Required Field is required."); }

# Do action here

# or if the calling form page was not a popup :
# WebTool::UI::redirect('index.cgi');