[html-formfu] How to restore information for the confirm page?
Carl Franks
fireartist at gmail.com
Thu Nov 27 09:01:16 GMT 2008
2008/11/27 Hu Hailin <i at h2l.name>:
> ------------------------------
> what i am expecting is something like
> $params_for_humans = {
> 'Your name' => 'Zhang San',
> 'Your city' => 'Shanghai'
> };
That sounds reasonable - with the following caveats:
* it would have to be an arrayref, not a hashref, otherwise you'd lose
the order of fields
* it couldn't handle any processors that do anything funky, such as
combining multiple field values into a single value.
off-hand, I think that means these wouldn't work with it:
Filter::CompoundJoin, Filter::CompoundSprintf,
Inflator::CompoundDateTime
* it would skip any Hidden fields, or fields without a label
* should it use param_value() to ensure there's a single value, or use
param() and make any code that uses it have to handle the possibility
of getting an array of values
It would probably look something like this:
sub presentational_params {
my ( $self ) = @_;
return [] if !$self->submitted;
my @output;
for my $name ( $self->valid ) {
my $field = $self->get_field( $name );
next if !defined $field;
my $label = $field->label;
next if !defined $label;
push @output, {
label => $label,
value => $self->param_value( $name ),
};
}
return @output;
}
That would return this data structure:
[
{
label => 'Your name',
value => 'Zhang San',
},
{
label => 'Your city',
value => 'Shanghai',
},
]
I picked that structure because it'd be easy to work with in TT, and I
hate anything that returns a hashref with a single key/value that you
need to deref (yes, I'm talking to you, Config::Any ;) )
For example:
[
{
'Your name' => 'Zhang San',
},
{
'Your city' => 'Shanghai',
},
]
> However, how do you guys handle the confirm page generally?
I generally don't - most of the stuff I do is typical CRUD, and after
adding / editing a record, I'll usually just redirect to the "view"
page for that particular record.
Carl
More information about the HTML-FormFu
mailing list