fixed: DataForm doesn't work properly with internationalized fields

fixed: incoming data not properly decoded from utf8
This commit is contained in:
Graham Knop 2008-08-22 21:23:40 +00:00
parent 2d3ca50c05
commit 3f4de3612f
3 changed files with 19 additions and 13 deletions

View file

@ -2,6 +2,8 @@
- remove Do Nothing On Delete workflow and allow none to be selected for on delete etc workflow
- remove remnants of realtime workflow selection code
- fixed: Asset view time format problem
- fixed: DataForm doesn't work properly with internationalized fields
- fixed: incoming data not properly decoded from utf8
7.5.22
- fixed: Layout template now gets prepared correctly

View file

@ -31,7 +31,7 @@ use WebGUI::Pluggable;
use WebGUI::DateTime;
use WebGUI::User;
use WebGUI::Group;
use JSON qw(encode_json decode_json);
use JSON;
our @ISA = qw(WebGUI::Asset::Wobject);
@ -170,7 +170,7 @@ sub _saveFieldConfig {
my @config = map {
$self->getFieldConfig($_)
} @{ $self->getFieldOrder };
my $data = encode_json(\@config);
my $data = JSON::to_json(\@config);
$self->update({fieldConfiguration => $data});
}
@ -179,7 +179,7 @@ sub _saveTabConfig {
my @config = map {
$self->getTabConfig($_)
} @{ $self->getTabOrder };
my $data = encode_json(\@config);
my $data = JSON::to_json(\@config);
$self->update({tabConfiguration => $data});
}
@ -343,7 +343,7 @@ sub definition {
defaultValue=>$i18n->get(2),
},
);
$properties{fieldConfiguration}{defaultValue} = JSON::encode_json(\@defFieldConfig);
$properties{fieldConfiguration}{defaultValue} = JSON::to_json(\@defFieldConfig);
push @$definition, {
assetName => $i18n->get('assetName'),
uiLevel => 5,
@ -361,7 +361,7 @@ sub _cacheFieldConfig {
if (!$self->{_fieldConfig}) {
my $jsonData = $self->get("fieldConfiguration");
my $fieldData;
if ($jsonData && eval { $jsonData = decode_json($jsonData) ; 1 }) {
if ($jsonData && eval { $jsonData = JSON::from_json($jsonData) ; 1 }) {
# jsonData is an array in the order the fields should be
$self->{_fieldConfig} = {
map { $_->{name}, $_ } @{ $jsonData }
@ -383,7 +383,7 @@ sub _cacheTabConfig {
if (!$self->{_tabConfig}) {
my $jsonData = $self->get("tabConfiguration");
my $fieldData;
if ($jsonData && eval { $jsonData = decode_json($jsonData) ; 1 }) {
if ($jsonData && eval { $jsonData = JSON::from_json($jsonData) ; 1 }) {
# jsonData is an array in the order the fields should be
$self->{_tabConfig} = {
map { $_->{tabId}, $_ } @{ $jsonData }
@ -449,7 +449,7 @@ sub deleteAttachedFiles {
if ($entryId) {
my $entry = $self->session->db->buildArrayRef("select entryData from DataForm_entry where assetId=? and DataForm_entryId=?", [$self->getId, $entryId]);
$entryData = decode_json($entry->{entryData});
$entryData = JSON::from_json($entry->{entryData});
}
if ($entryData) {
for my $field ( @$fields ) {
@ -463,7 +463,7 @@ sub deleteAttachedFiles {
else {
my $entries = $self->session->db->buildArrayRef("select entryData from DataForm_entry where assetId=?", [$self->getId]);
foreach my $entry (@{ $entries}) {
my $entryData = decode_json($entry);
my $entryData = JSON::from_json($entry);
for my $field (@{ $fields }) {
my $form = $self->_createForm($fieldConfig->{$field}, $entryData->{$field});
if ($form->can('getStorageLocation')) {
@ -514,7 +514,7 @@ sub getListTemplateVars {
FROM `DataForm_entry` WHERE `assetId` = ? ORDER BY `submissionDate` DESC", [$self->getId]);
while (my $record = $entries->hashRef) {
my $recordData;
if (!eval { $recordData = decode_json($record->{entryData}) ; 1 }) {
if (!eval { $recordData = JSON::from_json($record->{entryData}) ; 1 }) {
$self->session->errorHandler->warn('DataForm ' . $self->getId . ' entry ' . $record->{DataForm_entryId} . ' contains invalid data');
next;
}
@ -611,7 +611,7 @@ sub getRecordTemplateVars {
if ($var->{entryId}) {
$var->{"form.start"} .= WebGUI::Form::hidden($self->session,{name=>"entryId",value=>$var->{entryId}});
$entry = $self->getCollateral("DataForm_entry","DataForm_entryId",$var->{entryId});
$entryData = decode_json( $entry->{entryData} );
$entryData = JSON::from_json( $entry->{entryData} );
my $date = WebGUI::DateTime->new($self->session, $entry->{submissionDate})->cloneToUserTimeZone;
$var->{ipAddress} = $entry->{ipAddress};
$var->{username} = $entry->{username};
@ -1236,7 +1236,7 @@ sub www_exportTab {
my $outText = $tsv->print;
while (my $entryData = $entries->hashRef) {
my $entryFields = decode_json($entryData->{entryData});
my $entryFields = JSON::from_json($entryData->{entryData});
$tsv->combine(
$entryData->{DataForm_entryId},
$entryData->{ipAddress},
@ -1352,7 +1352,7 @@ sub www_process {
if ($entryId) {
my $entry = $self->getCollateral("DataForm_entry","DataForm_entryId", $entryId);
eval {
$entryData = decode_json($entry->{entryData});
$entryData = JSON::from_json($entry->{entryData});
};
}
@ -1398,7 +1398,7 @@ sub www_process {
$self->sendEmail($var, $entryData);
}
if ($self->get('storeData')) {
my $entryJSON = encode_json($entryData);
my $entryJSON = JSON::to_json($entryData);
my $collData = {
DataForm_entryId => $entryId,
userId => $self->session->user->userId,

View file

@ -16,6 +16,7 @@ package WebGUI::Session::Form;
use strict qw(vars subs);
use WebGUI::HTML;
use Encode;
use base 'WebGUI::FormValidator';
=head1 NAME
@ -106,6 +107,9 @@ sub param {
if ($field) {
if ($self->session->request) {
my @data = $self->session->request->param($field);
foreach my $value (@data) {
$value = Encode::decode_utf8($value);
}
return wantarray ? @data : $data[0];
} else {
return undef;