[html-formfu] populate with a variable

Carl Franks fireartist at gmail.com
Thu Feb 5 09:40:34 GMT 2009


2009/2/4 abhishek jain <abhishek.netjain at gmail.com>:
> friends,
> how can i populate a FormFu form with a yml config file with a variable
> defined on stash
> so i want something like
> c.stash.varhash.key
>
> printed in the form input text box.

To do this, I think you'd need to create a Plugin.
Something like this should work...

form config:

    elements:
      - name: foo
        plugins: DefaultFromContextStash
        stash_name: 'varhash.key'

Then the plugin would look something like this:
(completely untested, of course)

package HTML::FormFu::Plugin::DefaultFromContextStash;
use strict;
use base 'HTML::FormFu::Plugin';

use HTML::FormFu::ObjectUtil qw( get_nested_hash_value );

__PACKAGE__->mk_item_accessors('stash_name');

sub process {
    my ($self) = @_;

    my $context = $self->stash->{context}
        or return;

    my $stash_name = $self->stash_name
        or return;

    my $value = $self->get_nested_hash_value(
        $context->stash,
        $stash_name,
    );

    $self->parent->default( $value );

    return;
}

1;



More information about the HTML-FormFu mailing list