diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 03d112257..68c2a6aa3 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -10,6 +10,8 @@ - added ability to select which rich editor is used to compose messages in the inbox - removed random questions display from Survey Questions Edit template until that feature is added. + - fixed #9115: WebGUI::ProfileField->formField doesn't always show the submitted value + 7.6.9 - fixed: ukplayer example is now loaded with swfobject.js released under the MIT licence, see gotcha's and /extras/ukplayer - fixed #9264: new slideShow.swf uploaded in extras/ukplayer (United Knowledge/Arjan Widlak) diff --git a/lib/WebGUI/Form/CheckList.pm b/lib/WebGUI/Form/CheckList.pm index dae362c1b..c17247fb9 100644 --- a/lib/WebGUI/Form/CheckList.pm +++ b/lib/WebGUI/Form/CheckList.pm @@ -18,6 +18,7 @@ use strict; use base 'WebGUI::Form::List'; use WebGUI::Form::Checkbox; use WebGUI::Form::Button; +use WebGUI::Form::Hidden; use WebGUI::International; =head1 NAME @@ -129,6 +130,18 @@ sub isDynamicCompatible { #------------------------------------------------------------------- +=head2 isInRequest ( ) + +=cut + +sub isInRequest { + my $self = shift; + my $form = $self->session->form; + return $form->hasParam($self->privateName('isIn')); +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a series of checkboxes. @@ -136,8 +149,10 @@ Renders a series of checkboxes. =cut sub toHtml { - my $self = shift; + my $self = shift; + my $session = $self->session; my $output = '
'; + $output .= WebGUI::Form::Hidden($session, { name => $self->privateName('isIn'), value => 1, }); my $alignment = $self->alignmentSeparator; # Add the select all button @@ -153,7 +168,7 @@ sub toHtml { ? 1 : 0 ; - $output .= WebGUI::Form::Checkbox->new($self->session, { + $output .= WebGUI::Form::Checkbox->new($session, { name => $self->get('name'), value => $key, extras => $self->get('extras'), diff --git a/lib/WebGUI/Form/Control.pm b/lib/WebGUI/Form/Control.pm index c39c54f50..d9de1fdce 100644 --- a/lib/WebGUI/Form/Control.pm +++ b/lib/WebGUI/Form/Control.pm @@ -419,7 +419,7 @@ sub getOriginalValue { =head2 getDefaultValue ( ) -Returns the "defaultValue" passed in to the object in that order +Returns the "defaultValue". =cut @@ -454,10 +454,8 @@ Depricated. See getValue(). # getValueFromPost is deprecated, use getValue sub getValueFromPost { my $self = shift; - if ($self->session->request) { - my $value = $self->session->form->param($self->get("name")); - return $value if (defined $value); - } + my $value = $self->session->form->param($self->get("name")); + return $value if (defined $value); return $self->getDefaultValue; } @@ -475,6 +473,25 @@ sub isDynamicCompatible { #------------------------------------------------------------------- +=head2 isInRequest ( ) + +Object method that returns true if the form variables for this control exist in the +posted data from the client. This is required for all controls that are dynamic +compatible (->isDynamicCompatible=1). It should be overridden by any class that +changes the name of the form variable, or uses more than 1 named element per form. + +This method should only depend on the form name, and not secondary form properties +such as value, defaultValue or storage or asset id's. + +=cut + +sub isInRequest { + my $self = shift; + return $self->session->form->hasParam($self->get('name')); +} + +#------------------------------------------------------------------- + =head2 isProfileEnabled ( session ) Depricated. See isDynamicCompatible(). @@ -484,7 +501,6 @@ Depricated. See isDynamicCompatible(). sub isProfileEnabled { my $class = shift; - my $session = shift; return $class->isDynamicCompatible(); } diff --git a/lib/WebGUI/Form/File.pm b/lib/WebGUI/Form/File.pm index 306a7ddd0..5dc14984e 100644 --- a/lib/WebGUI/Form/File.pm +++ b/lib/WebGUI/Form/File.pm @@ -240,6 +240,21 @@ sub isDynamicCompatible { #------------------------------------------------------------------- +=head2 isInRequest ( ) + +=cut + +sub isInRequest { + my $self = shift; + my $form = $self->session->form; + my $name = $self->get('name'); + my $isInRequest = $form->hasParam($name.'_file') + || $form->hasParam($self->privateName('action')); + return $isInRequest; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a file upload control. diff --git a/lib/WebGUI/Form/Interval.pm b/lib/WebGUI/Form/Interval.pm index 23471f7af..71d07c7d3 100644 --- a/lib/WebGUI/Form/Interval.pm +++ b/lib/WebGUI/Form/Interval.pm @@ -143,6 +143,20 @@ sub isDynamicCompatible { #------------------------------------------------------------------- +=head2 isInRequest ( ) + +=cut + +sub isInRequest { + my $self = shift; + my $form = $self->session->form; + my $name = $self->get('name'); + return $form->hasParam($name.'_interval') + || $form->hasParam($name.'_units'); +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders an interval control. diff --git a/lib/WebGUI/Form/SelectList.pm b/lib/WebGUI/Form/SelectList.pm index ffbc17336..f2f1693ea 100644 --- a/lib/WebGUI/Form/SelectList.pm +++ b/lib/WebGUI/Form/SelectList.pm @@ -98,6 +98,19 @@ sub isDynamicCompatible { #------------------------------------------------------------------- +=head2 isInRequest ( ) + +=cut + + +sub isInRequest { + my $self = shift; + my $form = $self->session->form; + return $form->hasParam($self->privateName('isIn')); +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a select list form control. @@ -105,9 +118,10 @@ Renders a select list form control. =cut sub toHtml { - my $self = shift; + my $self = shift; + my $session = $self->session; my $multiple = $self->get("multiple") ? ' multiple="multiple"' : ''; - my $output = 'get("extras")||'').$multiple.'>'; my $options = $self->getOptions; my @values = $self->getOriginalValue(); foreach my $key (keys %{$options}) { @@ -120,6 +134,7 @@ sub toHtml { $output .= '>'.$options->{$key}.''; } $output .= ''."\n"; + $output .= WebGUI::Form::Hidden($session, { name => $self->privateName('isIn'), value => 1, }); return $output; } diff --git a/lib/WebGUI/ProfileField.pm b/lib/WebGUI/ProfileField.pm index ad1317a84..b62869a41 100644 --- a/lib/WebGUI/ProfileField.pm +++ b/lib/WebGUI/ProfileField.pm @@ -120,7 +120,7 @@ sub create { # Get the field's data type $properties->{fieldType} ||= "ReadOnly"; - my $formClass = 'WebGUI::Form::' . ucfirst $properties->{fieldType}; + my $formClass = $self->getFormControlClass; eval "use $formClass;"; my $dbDataType = $formClass->getDatabaseFieldType; @@ -545,6 +545,25 @@ sub isEditable { } +#------------------------------------------------------------------- + +=head2 isInRequest ( ) + +Returns a boolean indicating whether this field was in the posted data. + +=cut + +sub isInRequest { + my $self = shift; + my $session = $self->session; + my $form = WebGUI::Form::DynamicField->new($session, + fieldType => $self->get('fieldType'), + name => $self->getId, + ); + return $form->isInRequest; +} + + #------------------------------------------------------------------- =head2 isProtected ( ) @@ -812,7 +831,7 @@ sub set { # If the fieldType has changed, modify the userProfileData column if ($properties->{fieldType} ne $self->get("fieldType")) { # Create a copy of the new properties so we don't mess them up - my $fieldClass = "WebGUI::Form::".ucfirst($properties->{fieldType}); + my $fieldClass = $self->getFormControlClass; eval "use $fieldClass;"; my $dbDataType = $fieldClass->new($session, $self->formProperties($properties))->getDatabaseFieldType; diff --git a/lib/WebGUI/Session/Form.pm b/lib/WebGUI/Session/Form.pm index 0bd0332a2..f0625111e 100644 --- a/lib/WebGUI/Session/Form.pm +++ b/lib/WebGUI/Session/Form.pm @@ -66,6 +66,24 @@ sub AUTOLOAD { return $self->$method(@args); } +#------------------------------------------------------------------- + +=head2 hasParam ( $param ) + +Returns true if the param is part of the submitted form data, or a URL param. + +=cut + +sub hasParam { + my $self = shift; + my $param = shift; + return undef unless $param; + return undef unless $self->session->request; + my $hashRef = $self->session->request->param(); + return exists $hashRef->{$param}; +} + + #------------------------------------------------------------------- =head2 paramsHashRef ( ) diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index a2444622e..6181c5d0c 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -1170,23 +1170,21 @@ sub validateProfileDataFromForm { my $errorFields = []; my $warnFields = []; - foreach my $field (@{$fields}) { + FIELD: foreach my $field (@{$fields}) { my $fieldId = $field->getId; my $fieldLabel = $field->getLabel; my $fieldValue = $field->formProcess; my $isValid = $field->isValid($fieldValue); - $data->{$fieldId} = (ref $fieldValue eq "ARRAY") ? $fieldValue->[0] : $fieldValue; - if(!$isValid) { $errorCat = $field->get("profileCategoryId") unless (defined $errorCat); push (@{$errors}, sprintf($i18n->get("required error"),$fieldLabel)); push(@{$errorFields},$fieldId); } #The language field is special and must be always be valid or WebGUI will croak - elsif($fieldId eq "language" && !(exists $i18n->getLanguages()->{$data->{$fieldId}})) { + elsif($fieldId eq "language" && !(exists $i18n->getLanguages()->{$fieldValue})) { $errorCat = $field->get("profileCategoryId") unless (defined $errorCat); - push (@{$errors}, sprintf($i18n->get("language not available error"),$data->{$fieldId})); + push (@{$errors}, sprintf($i18n->get("language not available error"),$fieldValue)); push(@{$errorFields},$fieldId); } #Duplicate emails throw warnings @@ -1195,6 +1193,11 @@ sub validateProfileDataFromForm { push (@{$warnings},$i18n->get(1072)); push(@{$warnFields},$fieldId); } + + ##Do not return data unless the form field was actually in the posted data. + next FIELD unless $field->isInRequest; + $data->{$fieldId} = (ref $fieldValue eq "ARRAY") ? $fieldValue->[0] : $fieldValue; + } return {