Cagao has asked for the wisdom of the Perl Monks concerning the following question:

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.