John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

A form has "email" and "repeat email" to make sure the user didn't type it wrong. This seems to be becoming a popular trope.

So, is there a simple way to validate that with FormFu?

Replies are listed 'Best First'.
Re: FormFu email doubling
by Khen1950fx (Canon) on Mar 21, 2011 at 08:04 UTC
    Using HTML::FormFu::Constraint::Email to check for well-formedness:
    #!/usr/bin/perl use strict; use warnings; use HTML::FormFu::Constraint::Email; print (Email::Valid->address('somebody@somewhere.com') ? "yes\n": "no\ +n");
      Indeed I did that on the first email field.

      My question is how do I make it check that the second "repeat email" field is the same as the first "email" field?

Re: FormFu email doubling
by GrandFather (Saint) on Mar 21, 2011 at 08:56 UTC

    Either I'm being thick, or there is a hidden trap of some sort, or you can just if (isValid ($email1) && $email1 eq $email2).

    True laziness is hard work
      I don't want to call it after getting control back. I want the form to do that as part of its "validate" process, so it automatically interacts with the page and doesn't go through my code path that all is "submitted and validated".

      The instructions show "validators" as being classes. Seems overkill to write a class, in a separate file in a structured directory branch I don't even have now, to do a simple comparison.

      So, does this particular validator already exist, or is there a way to do equals between two fields (not just with constants) in the form definition, or can I just pass a code ref somewhere?

Re: FormFu email doubling
by fireartist (Chaplain) on Mar 21, 2011 at 21:41 UTC
      That's it! Thanks.

        Typo - it should have been:

        elements: - name: email constraints: - type: Email - type: Equal others: - repeat_email - name: repeat_email

        Thanks to ikegami for the heads-up

Re: FormFu email doubling
by Anonymous Monk on Mar 21, 2011 at 16:36 UTC
    HTML::FormFu::Constraint::Equal - Multi-field Equality Constraint