From: Shane L. <sr...@us...> - 2000-11-18 17:57:44
|
Update of /cvsroot/formmagick/formmagick In directory slayer.i.sourceforge.net:/tmp/cvs-serv22186 Modified Files: FormMagick.pm INSTALL testfm.xml Log Message: Integrated HTML::FormMaker usage for drawing form widgets. I think its built-in CGI data validation may be causing trouble here--- a fully-validated page won't go to the next page for some reason. Documented HTML::FormMaker usage in INSTALL, changed minor bits of testfm.xml. Index: FormMagick.pm =================================================================== RCS file: /cvsroot/formmagick/formmagick/FormMagick.pm,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** FormMagick.pm 2000/11/15 06:17:09 1.17 --- FormMagick.pm 2000/11/18 17:57:41 1.18 *************** *** 9,12 **** --- 9,20 ---- # # $Log$ + # Revision 1.18 2000/11/18 17:57:41 srl + # Integrated HTML::FormMaker usage for drawing form widgets. I think its + # built-in CGI data validation may be causing trouble here--- a + # fully-validated page won't go to the next page for some reason. + # + # Documented HTML::FormMaker usage in INSTALL, changed minor bits of + # testfm.xml. + # # Revision 1.17 2000/11/15 06:17:09 srl # Added some basic routines for creating input fields of types besides TEXT. *************** *** 242,245 **** --- 250,266 ---- } + my @definitions; + + use HTML::FormMaker; + my $formmaker = HTML::FormMaker->new(); + + # HTML::FormMaker uses nonstandard names for its form widgets. + # Here's how to convert them. + + my %type_conversions = ( + 'TEXT' => 'textfield', + 'CHECKBOX' => 'checkbox', + 'SELECT' => 'popup_menu', + ); while (my $fieldinfo = shift @fields ) { *************** *** 250,391 **** my $fieldname = $fieldinfo->{ID}; my $option_function = $fieldinfo->{OPTIONS}; ! ! print "<tr>\n"; ! print "<td>", localise($label), "</td)\n"; ! ! ! my $field_output = "<td>"; ! ! # output a form field based on what kind of field this is. ! # Yes, this is hairy, but each form input has _slightly_ different ! # ways of specifying its current values. Blech. ! ! # Should we break this out into its own routine? ! ! if ($type eq "TEXTAREA") { ! $field_output .= qq(<TEXTAREA NAME="$fieldname">); ! ! # look for a value from CGI or from the XML-specified default ! if (my $value = ($cgi->param($fieldname) || $fieldinfo->{DEFAULT})) { ! $field_output .= $value; ! } ! $field_output .= "</TEXTAREA>"; ! ! } elsif ($type eq "CHECKBOX") { ! $field_output .= qq(<INPUT TYPE="$type" NAME="$fieldname"); ! ! # figure out if it's checked or not, based on default values given. ! # if so, add " CHECKED " to $field_output. ! ! # close the tag. ! $field_output .= ">"; ! ! } elsif ($type eq "RADIO") { ! # we need to generate a group of buttons here with the same ! # name and different values. ! ! # this isn't right here; look at the form_post_event sub below ! # to see how to call the function named in $option_function. ! ! #my %options = $option_function; ! ! # testing values. ! my %options = { ! red => "Red", ! blue => "Blue", ! green => "Green", ! }; ! ! my $option_key; ! ! # call the function named by $options to get a hash of options. ! foreach $option_key (keys %options) { ! $field_output .= qq(<INPUT TYPE="$type" NAME="$fieldname" VALUE="$option_key"); ! # is this button checked or not? if so, ! # $field_output .= " CHECKED "; ! # close the tag. ! $field_output .= ">"; ! ! # label the button. ! $field_output .= $options{$option_key}; ! ! } ! ! ! } elsif ($type eq "SELECT") { ! # follow something very similar to the radiobuttons above, with different ! # tags. ! ! # HOW DO WE HANDLE MULTI-SELECTS IN SPECIFYING EXISTING VALUES? ! ! # this isn't right here; look at the form_post_event sub below ! # to see how to call the function named in $option_function. ! ! #my %options = $option_function; ! ! # testing values. this might be database data, for example. ! my %options = { ! 1 => 'good', ! 2 => 'bad', ! 3 => 'ugly', ! }; ! ! $field_output .= qq(<SELECT NAME="$fieldname" TYPE="$type">); ! ! # call the function named by $options to get a hash of options. ! # We'll need a hash because there's a value and a label, and ! # we might want both of those to be strings. ! ! my $option_key; ! ! # Gack. This is broken. ---srl ! ! foreach $option_key (keys %options) { ! $field_output .= qq(<OPTION VALUE="$option_key"); ! ! # is this item selected or not? if so, ! # $field_output .= " SELECTED "; ! ! # close the tag. ! $field_output .= ">"; ! ! # output a label for this option. ! $field_output .= $options{$option_key}; ! ! # close the tag. ! $field_output .= "</OPTION>"; ! ! } ! $field_output .= qq(</SELECT>); ! } else { # $type eq "TEXT" ! $field_output .= qq(<INPUT TYPE="$type" NAME="$fieldname"); ! if (my $value = ($cgi->param($fieldname) || $fieldinfo->{DEFAULT})) { ! $field_output .= qq( VALUE="$value">); ! } else { ! $field_output .= ">"; ! } ! } ! print "<td>$field_output</td>\n"; ! print "</tr>\n"; - # XXX This is implemented above, but I'll leave these in. - # - # handle options. this might be by making another tag like - # this one, with a different value (if this is a RADIOBUTTON or CHECKBOX - # field), or by outputting tags inside this one (for a SELECT, we'll need - # multiple OPTIONs). - # give a closing tag, if needed (for SELECT and TEXTAREA, I think.) - #if (($type eq "select") || ($type eq "textarea") ) { - # print "<\/$type>\n"; - #} - } } --- 271,313 ---- my $fieldname = $fieldinfo->{ID}; my $option_function = $fieldinfo->{OPTIONS}; ! my $value = $fieldinfo->{VALUE}; ! my $converted_type = $type_conversions{"$type"}; ! #print "type is $type, converted is $converted_type<br>"; ! my @values; ! if ($type eq "SELECT") { ! # use this for all SELECTs until we get the option_function call worked out ! # really we want to call option_function here, inside an exec--- first within ! # the scope of the script that uses this module, then within our own scope, ! # to get an array (hash) from option_function. ! @values = ["red", "blue", "green"]; ! } else { ! @values = [$value]; ! } + # i don't like how the "value" param below doesn't let us specify a separate + # value from the OPTION shown in the selectbox. Someone want to look more at + # HTML::FormMaker on this? + + my $definition = { + visible_title => localise($label), + type => "$converted_type", + name => "$fieldname", + value => @values, + }; ! push @definitions, $definition; ! } + $formmaker->field_definitions( \@definitions ); ! print ! $formmaker->make_html_input_form( 1 ), ! $formmaker->hr, ! $formmaker->new_form() ? '' : $formmaker->make_html_input_echo( 1 ); } Index: INSTALL =================================================================== RCS file: /cvsroot/formmagick/formmagick/INSTALL,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** INSTALL 2000/11/12 22:18:20 1.4 --- INSTALL 2000/11/18 17:57:41 1.5 *************** *** 11,14 **** --- 11,15 ---- Text::Template Data::Dumper + HTML::FormMaker The following are required by certain validation routines. If you don't Index: testfm.xml =================================================================== RCS file: /cvsroot/formmagick/formmagick/testfm.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** testfm.xml 2000/11/15 05:40:39 1.3 --- testfm.xml 2000/11/18 17:57:41 1.4 *************** *** 7,11 **** <FIELD ID="lastname" LABEL="Your surname" TYPE="TEXT" VALIDATION="nonblank"/> ! <FIELD ID="username" LABEL="Choose a username" TYPE="TEXT" VALIDATION="username, minlength(4)"/> <FIELD ID="group" LABEL="Choose a group" TYPE="SELECT" --- 7,11 ---- <FIELD ID="lastname" LABEL="Your surname" TYPE="TEXT" VALIDATION="nonblank"/> ! <FIELD ID="username" LABEL="Choose a username" TYPE="TEXT" VALUE="username" VALIDATION="username, minlength(4)"/> <FIELD ID="group" LABEL="Choose a group" TYPE="SELECT" |