diff options
author | Yorhel <git@yorhel.nl> | 2008-11-08 10:48:25 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2008-11-08 10:48:25 +0100 |
commit | 959b2b36ebe4a59ba7677b2a9d4a6ff3d66c6c49 (patch) | |
tree | 6ecf9fc32f515fd7f25f2e99df422f74c2e0ab33 /lib/VNDB/Util/FormHTML.pm | |
parent | b97be8e48ed7893200940684b564c4dd8be1f86a (diff) |
Made a start on the form generator
Just playing with a conceptual design at this point, the current
functions don't really do much yet
Diffstat (limited to 'lib/VNDB/Util/FormHTML.pm')
-rw-r--r-- | lib/VNDB/Util/FormHTML.pm | 72 |
1 files changed, 68 insertions, 4 deletions
diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm index a1f373a8..35528646 100644 --- a/lib/VNDB/Util/FormHTML.pm +++ b/lib/VNDB/Util/FormHTML.pm @@ -6,7 +6,7 @@ use warnings; use YAWF ':html'; use Exporter 'import'; -our @EXPORT = 'htmlFormError'; +our @EXPORT = qw| htmlFormError htmlFormPart htmlFormSub htmlForm |; # form error messages @@ -20,10 +20,16 @@ my %formerr_exeptions = ( # Displays friendly error message when form validation failed -# Argument is the return value of formValidate -sub htmlFormError { # $frm - my($self, $frm) = @_; +# Argument is the return value of formValidate, and an optional +# argument indicating whether we should create a special mainbox +# for the errors. +sub htmlFormError { + my($self, $frm, $mainbox) = @_; return if !$frm->{_err}; + if($mainbox) { + div class => 'mainbox'; + h1 'Error'; + } div class => 'warning'; h2 'Form could not be send:'; ul; @@ -51,7 +57,65 @@ sub htmlFormError { # $frm } end; end; + if($mainbox) { + end; + end; + } +} + + +# Generates a form part... +sub htmlFormPart { + +} + + +sub htmlFormSub { + my($self, $name, $parts) = @_; + fieldset; + legend $name; + table class => 'formtable'; + $self->htmlFormPart($_) for @$parts; + end; + end; +} + + +# Generates a form, first argument is a hashref with global options, keys: +# frm => the $frm as returned by formValidate, +# action => The location the form should POST to +# upload => 1/0, adds an enctype. +# The other arguments are a list of subforms in the form +# of (subform-name => [form parts]). Each subform is shown as a +# (JavaScript-powered) tab, if only one subform is specified, no tabs +# are shown and no 'mainbox' is generated. Otherwise, each subform has +# it's own 'mainbox'. This function automatically calls htmlFormError, +# and creates a separate mainbox for that if multiple subforms are specified. +sub htmlForm { + my($self, $options, @subs) = @_; + form action => '/nospam?'.$options->{action}, method => 'post', 'accept-charset' => 'utf-8', + $options->{upload} ? (enctype => 'multipart/form-data') : (); + if(@subs == 2) { + $self->htmlFormError($options->{frm}); + $self->htmlFormSub(@subs); + input type => 'submit', value => 'Submit', class => 'submit'; + } else { + $self->htmlFormError($options->{frm}, 1); + while(my($name, $parts) = (shift(@subs), shift(@subs))) { + last if !$name || !$parts; + (my $short = lc $name) =~ s/ /_/; + div class => 'mainbox subform', id => 'subform_'.$short; + h1 $name; + $self->htmlFormSub($name, $parts); + end; + } + div class => 'mainbox'; + input type => 'submit', value => 'Submit', class => 'submit'; + end; + } + end; } 1; + |