summaryrefslogtreecommitdiff
path: root/lib/VNDB/Util
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2015-10-03 10:15:53 +0200
committerYorhel <git@yorhel.nl>2015-10-03 10:15:53 +0200
commitb75eff0f2cce2050c98ec946aac28b390020fdc5 (patch)
tree2e34fdd690cb06b5f5cb12dbecaa3919e0d16ec6 /lib/VNDB/Util
parent30caa944332fbbb9f6f5a4805f5beeee2b8a506c (diff)
Handle JSON data natively when processing form data
No more need for extra json_encode/json_decode calls, and the form_compare() function is more lenient w.r.t. integer/string comparison. This is the improvement I described in commit ed86cfd12b0bed7352e2be525b8e63cb4d6d5448
Diffstat (limited to 'lib/VNDB/Util')
-rw-r--r--lib/VNDB/Util/FormHTML.pm7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm
index 611fdf46..9612f904 100644
--- a/lib/VNDB/Util/FormHTML.pm
+++ b/lib/VNDB/Util/FormHTML.pm
@@ -62,6 +62,7 @@ sub htmlFormError {
# and all other elements forming a hash with options specific to that type.
# Type Options
# hidden short, (value)
+# json short, (value) # Same as hidden, but value is passed through json_encode()
# input short, name, (width, pre, post)
# passwd short, name
# static content, (label, nolabel)
@@ -71,16 +72,16 @@ sub htmlFormError {
# text name, short, (rows, cols)
# date name, short
# part title
-# TODO: Find a way to write this function in a readable way...
sub htmlFormPart {
my($self, $frm, $fp) = @_;
my($type, %o) = @$fp;
local $_ = $type;
- if(/hidden/) {
+ if(/hidden/ || /json/) {
Tr class => 'hidden';
td colspan => 2;
- input type => 'hidden', id => $o{short}, name => $o{short}, value => $o{value}||$frm->{$o{short}}||'';
+ my $val = $o{value}||$frm->{$o{short}};
+ input type => 'hidden', id => $o{short}, name => $o{short}, value => /json/ ? json_encode($val||[]) : $val||'';
end;
end;
return