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')

In reply to HTML::FormHandler validate_form method by uG

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.