Hi All,

I seem to be having issues with Validation::Class not being able to do what I want... (tho I'm sure it's more likely user-error)

Part 1

Firstly, trying to deal with multi-valued parameters, ie, a select box on a form.

in MyApp::Form::Customer...
field industry => { required => 0, min_length => 1, max_length => 255, validation => sub { _validate_industry( @_ ) }, label => 'Industry', }; $form = MyApp::Form::Customer->new( params => { industry => [ $query->param('industry') ] } );
Basically this never gets to my validate method.

Part 2

My validation relies on 1 of 2 fields being filled in, I'm currently setting both fields to 'required => 0', then passing a default value of '-' to ensure my validate methods get fired...

sub _validate_keywords { my ($self, $this, $params) = @_; if ( $params->{ keywords } eq '-' && $params->{ industry } eq '-' +) { $self->error($this, "You must enter some keywords or choose an + industry."); } return 1; } sub _validate_industry { my ($self, $this, $params) = @_; if ( $params->{ keywords } eq '-' && $params->{ industry } eq '-' +) { $self->error($this, "You must enter some keywords or choose an + industry."); } return 1; } $form = MyApp::Form::Customer->new( params => { industry => $query +->param('industry') || '-', keywords => $query->pa +ram('keywords') || '-',
I'm sure I'm doing something wrong here, but unsure as to what that is. It's strikes me as odd that the validate methods don't get fired for an empty string. Not firing for undef I would expect.

Thanks in advance for any clues or guidance.

In reply to Validation::Class issues by Cagao

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.