#!/usr/local/bin/perl # # Code for a generic cgi wizard. The wizard save # for each stage in the process, provides validation of fields via # regular expressions, and manages button presses etc. It allows pages # to be used to enter multiple sets of values, all of which are stored. # # 1) create a wizard array. Each array element specifies # a page in the wizard. Each element should be a comma-separated # string, containing the following values: # - "page": the .cgi file for the page # - "min": the minimum valid number of datafiles # required for this page # - "max": the maximum valid number of datafiles # required for this page. # An example of a valid entry would be "page=mywizpage.cgi,min=1,max=1". # # The wizard allows pages to be used to enter multiple sets of # properties. Each wizard page has an associated data file, and # where multiple datafiles are valid (i.e. max_datafiles>1), # they are numbered monotonically. # 2) Create a .cgi file for each wizard page you specified in the # wizard array. Each wizard page will call wizard_header(), # wizard_[inputtype]() for each data field and wizard_footer(). # 3) Create a submit .cgi script that processes the set of datafiles # created. # # Appearance: # # Wizard consists of a main table holding 3 subtables # - the description/image table, taking up the LHS # - the data table, where fields appear, on the RHS # - the button table on the bottom # The data table is opened, and rows are added by calls # to wizard_input(). wizard_footer() adds the button table. # This variable is set to 0 whenever an element in the form fails to # validate against its regular expression. This prevents progress, and the # highlighted elements are marked in red. $validation_success = 1; # Creates tables/subtables, show image etc. # # Parameters: ref_to_array_of_wizard_element_hashes, pagename, heading, # description, imagename # sub wizard_header() { local ($wizinfo, %wizard, $wizref, $pagename, $heading, $description, $image); ($wizinfo, $pagename, $heading, $description, $image) = @_; %wizard = &read_in_wizard("$wizinfo"); $wizref = \%wizard; $pageinst = &wizard_get_pageinst(); $submit = &get_wizard_info_by_name($wizref, "submit"); print "
\n"; # if we are validating page, ensure that we redirect! if ($validation_success == 1) { # do redirect if next page/inst are defined &wizard_redirect_next($pagename, $pageinst); } } sub wizard_input() { local ($pagename, $description, $name, $size, $validation_regexp, $validation_err, $pageinst, $value); ($pagename, $description, $name, $size, $validation_regexp, $validation_err) = @_; $value = &wizard_form_input_header($pagename, $description, $name, $validation_regexp, $validation_err); print "\n"; &wizard_form_input_footer(); } sub wizard_textarea() { local ($pagename, $description, $name, $rows, $cols, $validation_regexp, $validation_err, $pageinst, $value); ($pagename, $description, $name, $rows, $cols, $validation_regexp, $validation_err) = @_; $value = &wizard_form_input_header($pagename, $description, $name, $validation_regexp, $validation_err); print "\n"; &wizard_form_input_footer(); } sub wizard_select() { local ($pagename, $description, $name, $selection_arrayref, $validation_regexp, $validation_err, $pageinst, $value, @array, $elt, $select); ($pagename, $description, $name, $selection_arrayref, $validation_regexp, $validation_err) = @_; $value = &wizard_form_input_header($pagename, $description, $name, $validation_regexp, $validation_err); print "\n"; &wizard_form_input_footer(); } # subfns used for wizard form inputs... sub wizard_form_input_header() { local ($pagename, $description, $name, $validation_regexp, $validation_err, $pageinst, $value); ($pagename, $description, $name, $validation_regexp, $validation_err) = @_; $pageinst = &wizard_get_pageinst(); $value = &wizard_get_data_value($pagename, $pageinst, $name); &wizard_validate_input($value, $validation_regexp, $validation_err); print "$description