use strict;
use vars qw($VERSION);
-$VERSION = '0.05';
+$VERSION = '0.06';
=head1 NAME
'options' => \%options,
'form_name' => 'dummy',
'form_action' => 'process.cgi',
- 'form_text' => [ qw( textfield1 textfield2 ) ],
- 'form_checkbox' => [ qw( checkbox1 ) ],
- 'form_radio' => [ qw( radio1 ) ],
- 'form_select' => [ qw( select1 ) ],
+
+ #new code auto-detects form types (radio not yet supported)
+ #'form_elements' => [ qw( textfield1 textfield2 checkbox1 radio1 select1 ) ],
+ 'form_elements' => [ qw( textfield1 textfield2 checkbox1 radio1 select1 ) ],
+
+ #deprecated style still works for now
+ #'form_text' => [ qw( textfield1 textfield2 ) ],
+ #'form_checkbox' => [ qw( checkbox1 ) ],
+ #'form_radio' => [ qw( radio1 ) ],
+ #'form_select' => [ qw( select1 ) ],
+
'layer_callback' => sub {
my $layer = shift;
my $html = qq!<INPUT TYPE="hidden" NAME="layer" VALUE="$layer">!;
This HTML generated by this module uses JavaScript, but nevertheless attempts
to be as cross-browser as possible. The 0.05 release drops Navigator 4
compatibility and has been tested under Mozilla Firefox 1.0.6, MSIE 6.0,
-Konqueror 3.3.2, and Opera 8.0.2.
+Konqueror 3.3.2, and Opera 8.0.2 (2006 note: still working under newer
+browsers such as IE7, Firefox 2.0, etc.).
=head1 FORMS
form_action - Form action
+form_elements - (optional) Array reference of form fields to copy from the
+ B<form_name> form. Field type is autodetected; currently
+ text, hidden, checkbox, and select (single) fiels are
+ supported. Select (multiple) and radio fields are not yet
+ supported.
+
form_text - (optional) Array reference of text (or hidden) form fields to copy
from the B<form_name> form.
my $between = exists($self->{html_between}) ? $self->{html_between} : '';
my $options = $self->{options};
my $form_action = exists($self->{form_action}) ? $self->{form_action} : '';
+
+ my $form_elements =
+ exists($self->{form_elements}) ? $self->{form_elements} : [];
my $form_text =
exists($self->{form_text}) ? $self->{form_text} : [];
my $form_checkbox =
$html .= <<END;
<FORM NAME="${key}$layer" ACTION="$form_action" METHOD=POST onSubmit="${key}fixup(this)" STYLE="margin-top: 0; margin-bottom: 0">
END
- foreach my $f ( @$form_text, @$form_checkbox, @$form_radio, @$form_select )
+ foreach my $f ( @$form_elements, @$form_text, @$form_checkbox, @$form_radio, @$form_select )
{
$html .= <<END;
<INPUT TYPE="hidden" NAME="$f" VALUE="">
my $self = shift;
my $key = exists($self->{unique_key}) ? $self->{unique_key} : '';
my $form_name = $self->{form_name} or return '';
+
+ my $form_elements =
+ exists($self->{form_elements}) ? $self->{form_elements} : [];
my $form_text =
exists($self->{form_text}) ? $self->{form_text} : [];
my $form_checkbox =
exists($self->{form_radio}) ? $self->{form_radio} : [];
my $form_select =
exists($self->{form_select}) ? $self->{form_select} : [];
- my $html = "
+ my $html = <<END;
<SCRIPT>
+
+function copyelement(from, to) {
+ if ( from == undefined ) {
+ to.value = '';
+ } else if ( from.type == 'select-one' ) {
+ to.value = from.options[from.selectedIndex].value;
+ //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
+ } else if ( from.type == 'checkbox' ) {
+ if ( from.checked ) {
+ to.value = from.value;
+ } else {
+ to.value = '';
+ }
+// } else if ( from.type == 'radio' ) {
+ } else {
+ if ( from.value == undefined ) {
+ to.value = '';
+ } else {
+ to.value = from.value;
+ }
+ }
+ //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
+}
+END
+
+ $html .= "
function ${key}fchanged(what) {
${key}fixup(what.form);
}
function ${key}fixup(what) {\n";
+ foreach my $f ( @$form_elements ) {
+ $html .= "copyelement( document.$form_name.elements['$f'],
+ what.elements['$f']
+ )\n";
+ }
+
foreach my $f ( @$form_text ) {
$html .= "what.$f.value = document.$form_name.$f.value;\n";
}