add process() sub for FormBuilder
This commit is contained in:
parent
72d32d679d
commit
72667d0bd1
1 changed files with 31 additions and 0 deletions
|
|
@ -80,6 +80,37 @@ sub addObjectAt {
|
|||
return $object;
|
||||
}
|
||||
|
||||
=head2 process ( )
|
||||
|
||||
Process the form and return a hashref of values.
|
||||
|
||||
=cut
|
||||
|
||||
sub process {
|
||||
my ( $self ) = @_;
|
||||
my $values = {};
|
||||
for my $obj ( @{$self->objects} ) {
|
||||
if ( $obj->isa( 'WebGUI::Form::Control' ) ) {
|
||||
$values->{ $obj->get('name') } = $obj->getValue;
|
||||
}
|
||||
elsif ( $obj->does( 'WebGUI::FormBuilder::Role::HasObjects' ) ) {
|
||||
my $merge = $obj->process;
|
||||
for my $key ( keys %$merge ) {
|
||||
if ( $values->{ $key } ) {
|
||||
if ( !ref $values->{ $key } ) {
|
||||
$values->{ $key } = [ $values->{ $key } ];
|
||||
}
|
||||
push @{ $values->{ $key } }, $merge->{ $key };
|
||||
}
|
||||
else {
|
||||
$values->{ $key } = $merge->{ $key };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
=head2 toTemplateVars ( prefix, var )
|
||||
|
||||
Get all the objects as a set of template vars with the given prefix. $var is
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue