On Sun, Jan 23, 2005 at 02:40:57PM +0000, Dave Howorth wrote:
>
> and I'm too lazy to compare the source, so if someone
> >could point it out to me, I'd be grateful. In most of my
> >other apps I override do_edit to use Data::FormValidator
> >instead, but I was trying to keep this simple, because I don't
> >actually have any validation needs.
>
> I'm interested to try Data::FormValidator with Maypole as well. Yours is
> the first posting I've seen from somebody who's tried it. Would you mind
> posting some code (your do_edit?) and/or sharing your experience?
It's incredibly simple, and pretty much drops right in place in
Maypole, with the DFV profile and the needed changes in do_edit.
In my driver class, I have something like:
--- SlangDB->config->{slangbiblio}{dfv_profile} = { optional => [qw /author title pub_date pub_location format pages publisher bib_author bib_source bib_date dib_info holding_lib shelfmark type category status brief_description description last_modified_by/], required => [qw /title/], constraints => { format => qr/^\d+$/, type => qr/^\d+$/, category => qr/^\d+$/, status => qr/^\d+$/, }, filters => 'trim', missing_optional_valid => 1, }; ---(Here the constraints are all to foreign keys for other tables; I don't have any real constraints, but you get the idea.)
Then, I change bits of do_edit like so (I can't quickly show you the whole thing, because I've mucked with parts of it for other reasons, but it should be obvious):
--- my $results = Data::FormValidator->check($r->{params}, $r->{config}{$r->{table}}{dfv_profile});
if ($results->has_invalid or $results->has_missing) { my $errors = $results->msgs; # Set it up as it was: $r->{template_args}{cgi_params} = $r->{params}; $r->{template_args}{errors} = $errors; $r->{template} = "edit";
} else {
my %valid_params = %{$results->valid};
if ($obj) { # We have something to edit $obj->set(%valid_params); $obj->update; } else { # new record $obj = $self->create(\%valid_params); $creating++; } $r->{template} = "view"; } ---
And that's pretty much it. Works like a charm.
HTH.
Best,
Jesse
_______________________________________________ maypole mailing list maypole at lists.netthink.co.uk http://lists.netthink.co.uk/listinfo/maypole
This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT