Fix handling of multi-form and multiple select form elements by emitting
a hidden form variable to make sure the form element was in the generated form. Changes in User and ProfileField to support this.
This commit is contained in:
parent
83d1203de9
commit
41da738e0e
9 changed files with 134 additions and 17 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 = '<fieldset style="border:none;margin:0;padding:0">';
|
||||
$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'),
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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 = '<select name="'.($self->get("name")||'').'" size="'.($self->get("size")||'').'" id="'.($self->get('id')||'').'" '.($self->get("extras")||'').$multiple.'>';
|
||||
my $output = '<select name="'.($self->get("name")||'').'" size="'.($self->get("size")||'').'" id="'.($self->get('id')||'').'" '.($self->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}.'</option>';
|
||||
}
|
||||
$output .= '</select>'."\n";
|
||||
$output .= WebGUI::Form::Hidden($session, { name => $self->privateName('isIn'), value => 1, });
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 ( )
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue