[html-formfu] Perl DBI with FormFu

Manu Kaul manu.kaul at gmail.com
Tue Mar 17 10:09:27 GMT 2009


Hi,I am still trying to get my head around how FormFu works and still
reading through the documentation to understand what is possible and what is
not. So bear with me if I am not making sense :)
But I want to be able to list out all the validations that are required on
the form i.e. required fields, checking field lengths, checking field values
against regular expressions, etc in the Config::General XML file. And then
use that in my Catalyst project with FormFu.
But instead of going   $form->create() or  $form->update... which will use
FormFu::Model::DBIC I think, I want to be able to pass the form values to a
custom method written in my Model class.
Also was wondering how I can then display the DEFAULT values for a form when
in EDIT mode, when I have a custom Model class in the background.
Is it possible for you to provide me some sample code that caters to what I
am doing or point me out some sample projects that are using FormFu so I can
see how the configuration aspects of form validation will work. Then I can
work on passing these off (once past validation) to my custom Perl DBI MODEL
class.
Hope this is making sense?


Cheers,
MK

On Tue, Mar 17, 2009 at 9:59 AM, Carl Franks <fireartist at gmail.com> wrote:

> 2009/3/17 Manu Kaul <manu.kaul at gmail.com>:
>
> Hi Manu,
>
> If you create custom constraints + validators, then can access your
> Catalyst context, and so access your model.
>
> If you're using Catalyst-Controller-HTML-FormFu, it'll automatically
> copy the Cat context into
>    $form->stash->{context};
>
> As an example of how to use it, here's a (slightly edited) part of the
> new Validator docs:
>
> =3Dhead1 BEST PRACTICES
>
> Try to avoid using callbacks if possible. Below is a more maintainable
> and reusable approach, which also keeps the code out of the controller.
>
> A normal application's directory would contain:
>
>    lib/HTML/FormFu/Constraint/MyApp/
>    lib/HTML/FormFu/Validator/MyApp/
>    lib/HTML/FormFu/Plugin/MyApp/
>    etc.
>
> Then, the form config file would just need:
>
>    validator: 'MyApp::SomeValidator'
>
> And the class would be something like this:
>
>    package HTML::FormFu::Validator::MyApp::SomeValidator;
>    use strict;
>    use warnings;
>    use base 'HTML::FormFu::Validator';
>
>    sub validate_value {
>        my ( $self, $value, $params ) =3D @_;
>
>        my $c =3D $self->form->stash->{context};
>
>        # do something here with $c->model('MyModel');
>        # return 1 if valid
>
>        # fail
>        return 0;
>    }
>
>    1;
>
> Hope this helps,
> Carl
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>



-- =


The greater danger for most of us lies not in setting our aim too high and
falling short; but in setting our aim too low, and achieving our mark.
- Michelangelo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20090317/ef=
72b4ab/attachment-0001.htm


More information about the HTML-FormFu mailing list