Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

HTML::FormHandler validate_form method

by uG (Scribe)
on Apr 08, 2010 at 01:09 UTC ( #833421=perlquestion: print w/replies, xml ) Need Help??
uG has asked for the wisdom of the Perl Monks concerning the following question:

package MediaBlogger::Form::Admin::Create_Post; use strict; use warnings; use HTML::FormHandler::Moose; extends 'HTML::FormHandler::Model::DBIC'; with 'HTML::FormHandler::Render::Table'; has '+item_class' => ( default => 'Post' ); has_field 'my_file' => ( type => 'Upload', required => 1 ); has_field 'affiliates' => ( type => 'Select', widget => 'radio_group', + multiple => 0, required => 1, options => [{ value => 'new', label => 'Ne +w'}, { value => 'old', label => 'Old' }, { value => 'none', label => +'None'} ] ); has_field 'affiliate_link' => ( type => 'Text' ); has_field 'short_affiliate_link' => ( type => 'Text' ); has_field 'title' => ( type => 'Text', required => 1 ); has_field 'description' => ( type => 'Text', required => 1 ); has_field 'submit' => ( type => 'Submit', value => 'Submit' ); has '+dependency' => ( default => sub { [ ['affiliate_link', 'short_affiliate_link'],] } ); before 'validate_form' => sub { my $self = shift; my $required = 0; if( $self->params('affiliates') eq 'new' ) { $required = 1; } $self->field('affiliate_link')->required($required); $self->field('short_affiliate_link')->required($required); };

Hello monks. After messing with various html frameworks i've finally decided on HTML::FormHandler. However I am having a problem with the before 'validate_form' method. I followed the example in the cookbook:

What I expect my code to do is set affiliate_link and short)affiliate_link's required flag to 1 (required => 1) only if the radio group has marked the radio button with the value of 'new'. However when I try and submit the form I get the following error:

Caught exception in MediaBlogger::Controller::Admin->sets "Attribute ( +params) does not pass the type constraint because: Validation failed +for 'HashRef' failed with value affiliates at C:\Catalyst App2\MediaB +logger\lib/MediaBlogger/Form/Admin/ line 29

Line 29 is the following piece of code from the top of this post:

if( $self->params('affiliates') eq 'new' ) {

So why doesn't this act like I expect it to? I assume its a problem with the way i'm accessing the value of a radiobox, but what am I doing wrong?


There is an error in the documentation. It should be $self->params->{affiliates} instead of $self->params('affiliates')

Replies are listed 'Best First'.
Re: HTML::FormHandler validate_form method
by actualize (Monk) on Apr 08, 2010 at 07:28 UTC
    Hello uG,

    Could you post your controller code?
    I don't really see anything that sticks out as wrong in your form code.

      I made an edit to the bottom of the post with the problem/solution. The documentation said to use:
      when it should have been:
      I got HTML::FormHandler's IRC channel and informed them and they have now corrected the documentation.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://833421]
Approved by AnomalousMonk
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2018-06-23 18:13 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.