summaryrefslogtreecommitdiff
path: root/lib/VNDB/Util/FormHTML.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-11-09 11:23:13 +0100
committerYorhel <git@yorhel.nl>2008-11-09 11:23:13 +0100
commitebd40d31732d395e627244a176e01bc72106156c (patch)
tree39e7e76500c5d33d53e1cd3f3b6d8fc06156f735 /lib/VNDB/Util/FormHTML.pm
parent805cb0824654e36e9558de345a4cc41aefea02ed (diff)
Added some functionality to the form generator and finished the login form
The layout of the form isn't the best and the form generator isn't dynamic enough to build beautiful forms, but it is pretty powerful and should make it very easy to write large forms. Rapid development > Design (a.k.a. writing forms manually is a pain in the ass)
Diffstat (limited to 'lib/VNDB/Util/FormHTML.pm')
-rw-r--r--lib/VNDB/Util/FormHTML.pm50
1 files changed, 41 insertions, 9 deletions
diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm
index 35528646..8718195d 100644
--- a/lib/VNDB/Util/FormHTML.pm
+++ b/lib/VNDB/Util/FormHTML.pm
@@ -51,7 +51,7 @@ sub htmlFormError {
$rule eq 'url' ? '%s: Invalid URL' :
$rule eq 'asciiprint' ? '%s may only contain ASCII characters' :
$rule eq 'int' ? '%s: Not a valid number' :
- $rule eq 'pname' ? '%s can only contain alphanumberic characters and a hyphen, and must start with a character' : '',
+ $rule eq 'pname' ? '%s can only contain lowercase alphanumberic characters and a hyphen, and must start with a character' : '',
$field;
}
}
@@ -64,18 +64,45 @@ sub htmlFormError {
}
-# Generates a form part...
+# Generates a form part.
+# A form part is a arrayref, with the first element being the type of the part,
+# and all other elements forming a hash with options specific to that type.
+# Type Options
+# input short, name, width
+# passwd short, name
+# static content
sub htmlFormPart {
-
+ my($self, $frm, $fp) = @_;
+ my($type, %o) = @$fp;
+ local $_ = $type;
+ Tr !/static/ ? (class => 'newfield') : ();
+ td class => 'label';
+ label for => $o{short}, $o{name} if $o{short} && $o{name};
+ lit '&nbsp;' if !$o{short} || !$o{name};
+ end;
+ td class => 'field';
+ if(/input/) {
+ input type => 'text', class => 'text', name => $o{short}, id => $o{short},
+ value => $frm->{$o{short}}||'', $o{width} ? (style => "width: $o{width}px") : ();
+ }
+ if(/passwd/) {
+ input type => 'password', class => 'text', name => $o{short}, id => $o{short},
+ value => $frm->{$o{short}}||'';
+ }
+ if(/static/) {
+ lit $o{content};
+ }
+ end;
+ end;
}
sub htmlFormSub {
- my($self, $name, $parts) = @_;
+ my($self, $frm, $name, $parts) = @_;
fieldset;
legend $name;
table class => 'formtable';
- $self->htmlFormPart($_) for @$parts;
+ $self->htmlFormPart($frm, $_) for @$parts;
end;
end;
}
@@ -97,20 +124,25 @@ sub htmlForm {
$options->{upload} ? (enctype => 'multipart/form-data') : ();
if(@subs == 2) {
$self->htmlFormError($options->{frm});
- $self->htmlFormSub(@subs);
- input type => 'submit', value => 'Submit', class => 'submit';
+ $self->htmlFormSub($options->{frm}, @subs);
+ fieldset class => 'submit';
+ input type => 'submit', value => 'Submit', class => 'submit';
+ end;
} else {
$self->htmlFormError($options->{frm}, 1);
+ # tabs here...
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);
+ $self->htmlFormSub($options->{frm}, $name, $parts);
end;
}
div class => 'mainbox';
- input type => 'submit', value => 'Submit', class => 'submit';
+ fieldset class => 'submit';
+ input type => 'submit', value => 'Submit', class => 'submit';
+ end;
end;
}
end;