Ryan Tate | 4 Mar 02:21

[FormBuilder] requiring any of several fields

As far as I can tell, there is no way to require that any one of
several fields be present.

I have an app where I need either field1 or field2 filled out. Neither
on its own is required, and a validate method attached to either field
would not detect when both are empty because it would never get
called!

The workaround for me is to inspect the form after it is submitted,
andmake sure one of the fields is set. If not, I mark one field as
invalid and set its message to something useful, then send the form
back to the user.

What would be more useful would be a formwide_validate callback that
checks the whole form, as opposed to a particular field like normal
validate. This would be the logical place to do what I'm trying to
accomplish.

$form->formwide_validate(sub{
  my $form = shift;
  ($form->field('foo') || $form->field('bar')) or return;
  return 1;
});
_______________________________________________
FBusers mailing list
FBusers <at> formbuilder.org
http://www.formbuilder.org/mailman/listinfo/fbusers

Nate Wiger | 4 Mar 04:03
Picon

Re: [FormBuilder] requiring any of several fields

On 3/3/07, Ryan Tate <lists <at> ryantate.com> wrote:
> As far as I can tell, there is no way to require that any one of
> several fields be present.

Have you tried using the FormBuilder Data::FormValidator support?

-Nate
_______________________________________________
FBusers mailing list
FBusers <at> formbuilder.org
http://www.formbuilder.org/mailman/listinfo/fbusers

Ryan Tate | 4 Mar 22:07

Re: [FormBuilder] requiring any of several fields

On 3/3/07, Nate Wiger <nwiger <at> gmail.com> wrote:
> Have you tried using the FormBuilder Data::FormValidator support?

No, I had not! Thanks for the pointer. I see now this case (requiring
any one of several fields) is cited specifically in the docs, sorry
for missing it.

So if I pass a D::FV obj as the validate argument to
CGI::FormBuilder->new, will the additional validation I set up for
various fields still work? ie can I still do
$form->field(name=>'email',required=>1,validate=>'EMAIL');
? Or do I have to do everything through the D::FV object?

Looks nice.
_______________________________________________
FBusers mailing list
FBusers <at> formbuilder.org
http://www.formbuilder.org/mailman/listinfo/fbusers

Nate Wiger | 5 Mar 04:02
Picon

Re: [FormBuilder] requiring any of several fields

On 3/4/07, Ryan Tate <lists <at> ryantate.com> wrote:
> On 3/3/07, Nate Wiger <nwiger <at> gmail.com> wrote:
> > Have you tried using the FormBuilder Data::FormValidator support?
>
> No, I had not! Thanks for the pointer. I see now this case (requiring
> any one of several fields) is cited specifically in the docs, sorry
> for missing it.
>
> So if I pass a D::FV obj as the validate argument to
> CGI::FormBuilder->new, will the additional validation I set up for
> various fields still work? ie can I still do
> $form->field(name=>'email',required=>1,validate=>'EMAIL');
> ? Or do I have to do everything through the D::FV object?

You have to use the D::FV object for everything, but FB does bridge
the gap by automatically detecting invalid fields/etc. So you can set
messages, but not validations thru field()

-Nate
_______________________________________________
FBusers mailing list
FBusers <at> formbuilder.org
http://www.formbuilder.org/mailman/listinfo/fbusers


Gmane