Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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:

http://search.cpan.org/~gshank/HTML-FormHandler-0.30003/lib/HTML/FormHandler/Manual/Cookbook.pod#Changing_required_flag

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/Create_Post.pm 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?

EDIT

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

Comment on HTML::FormHandler validate_form method
Select or Download Code
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:
      $self->params('affiliates')
      when it should have been:
      $self->params->{affiliates}
      I got HTML::FormHandler's IRC channel and informed them and they have now corrected the documentation.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://833421]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2014-12-28 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls