Hi Michael,

This is very similar to how I setup my error messages as well.  I like
them in the template, because I don't care what the message actually
says, as that should be up to the designers.

And I ran into the same issue as you with multiple constraints for a
single parameter, so I ended up rolling my own solution that works
pretty much exactly as C::A::P::VRM, except that it creates a
multi-dimentional hash for multiple constraints.  It usually looks
something like this:

errors => {
  invalid ={
    foo => 1
    bar => {
      length => 1,
      duplicate => 1,
    },
  },
  missing => {
    foobar => 1
  }
};

This structure works really easily with Template Toolkit because of
the magic dot notation:

[% IF errors.invalid.bar %]There was a problem with bar[% END %]

or I can get more details about what was actually wrong with bar:

[% IF errors.invalid.bar.duplicate %]That bar already exists[% END %]

It is a subtle difference from the way DFV builds the structure, but
it is enough that I can't use C::A::P::VRM.  I've tried to come up
with ways to patch CAP::VRM or DFV to overcome this, but I haven't
thought of anything worthwhile.

So I guess to summarize this longwinded answer, I have the same issue,
but I don't have an answer for you...

Cheers,

Cees

On 7/18/05, Michael Peters <[EMAIL PROTECTED]> wrote:
> Currently we use D::FV (with C::A::P::VRM) with msgs such that an error
> msgs named 'err_foo' will be passed into the templates. Basically like this:
> 
> sub show_stuff {
>   my ($self, $error_msgs) = @_;
>   my $tmpl = $self->load_tmpl(...);
>   if( $error_msgs ) {
>     $tmpl->param(%$error_msgs);
>   }
> 
>   return $tmpl->output();
> }
> 
> 
> sub do_stuff {
>   my $self = shift;
>   my $profile = {
>     required    => [qw(foo blah)],
>     constraints => {
>       foo  => qr/_foo$/,
>     },
>     msgs        => {
>       prefix            => 'err_',
>       any_errors        => 'any_errors',
>       format            => '%s',
>       missing           => 1,
>       invalid           => 1,
>       invalid_seperator => '',
>     },
>   };
> 
> This allows me to put the complete error message in the template and for
> the 'err_foo' param to just be a flag (with a value of 1). This works
> exactly like I want it to, but If I try to add multiple constraints on
> the same value like so:
> 
>     constraints => {
>       blah => [
>         {
>           name       => 'ends_in_blah',
>           constraint => qr/blah$/,
>         },
>         {
>           name       => 'begins_with_blah',
>           constraint => qr/^blah/,
>         }
>       ],
>     },
> 
> I would like to get not only a flag named 'err_blah' but also a flag
> named 'err_ends_in_blah' and/or 'err_begins_with_blah' so that my error
> messages in my template can do the right thing based on which of the
> multiple constraints failed. Is this a reasonable request? Is there a
> workaround or another way to accomplish this?
> 
> --
> Michael Peters
> Developer
> Plus Three, LP
> 
> 
> ---------------------------------------------------------------------
> Web Archive:  http://www.mail-archive.com/[email protected]/
>               http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to