[html-formfu] force error on field?

Carl Franks fireartist at gmail.com
Tue Sep 25 14:19:15 GMT 2007

On 25/09/2007, Josef Chladek <josef.chladek at gmail.com> wrote:
> hello,
> I read that one should not use the DBIC::Unique constraint - so I eval:

Although it won't be in the core until there's a consistent DBIC
interface, there's nothing to stop you using it for now if you don't
mind using non-cpan modules.

> eval {$row->populate_from_formfu( $c->stash->{form} );};
> and then check if $@ has the message "Duplicate entry ... for key
> 'email'"
> how would I now set the error for the field 'email' in my form? or

You'll need a constraint especially for that error - you could use a
Callback, as that always passes if you don't provide a callback()
routine - so it won't interfere in any way.

  - name: email
  - constraints:
    type: Callback
    message: 'Email already taken'

Then, after your test:

if ( $@ =~ m/duplicate entry for key 'email'/i ) {
    # then redisplay the form as normal

You'll also need to update to svn version 426, as I've just fixed a
bug with force_errors().


More information about the HTML-FormFu mailing list