FormFu - trying to make forms suck less

Well, google this title and it'll return almost 2 million results - so it's not an original idea, but it's worth a try. So how far along have we come this past year?

My favourite new feature is "method name suffixes" in Catalyst-Controller-HTML-FormFu which allow you to split up your code into blocks that will only be called depending on the state of the current form. E.g.

sub edit : Chained('group') : PathPart : Args(0) : FormConfig { }

sub edit_FORM_VALID {
    my ( $self, $c ) = @_;

    my $form  = $c->stash->{form};
    my $group = $c->stash->{group};

    $form->model->update( $group );

    $c->response->redirect( $c->uri_for( '/group', $group->id ) );
}

sub edit_FORM_NOT_SUBMITTED {
    my ( $self, $c ) = @_;

    my $form  = $c->stash->{form};
    my $group = $c->stash->{group};

    $form->model->default_values( $group );
}

I personally much prefer this to the usual if / elsif logic you'd otherwise need.

A great example of trying to make it as simple as possible to do the right thing... add request_token_enable: 1 to your Catalyst config for Catalyst-Controller-HTML-FormFu and it'll automatically add support to stop cross-site request forgeries (XSRF), to every form your application serves.

A good number of the updates and fixes, though, aren't of any note on their own, but are geared towards ensuring that $form->model->update( $row ) is smarter and more robust at updating your database with the least intervention possible - in particular, much better handling of Repeatable elements for representing has-many and many-to-many related rows.

So, nothing ground breaking, but hopefully enough to let you not have to think about most of the forms in your application, and make the remainder almost bearable!

Leave a comment

About fireartist

user-pic I blog about Perl.