The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

HTML::FormEngine::Checks - collection of FormEngine check routines

CHECK ROUTINES

not_null

Returns value missing if the field wasn't filled.

check_email

Returns invalid if the format of the field value seems to be incompatible to an email address. Here a simple regular expression is used, which so far matches the common email addresses. But it isn't compatible to any standard. Use rfc822 if you want to check for RFC compatible address format. The problem with rfc is, that some working addresses don't fit to it, though these are very rare

Here is the used regexp, please inform me if you discover any bugs:

^[A-Za-z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$

rfc822

Returns rfc822 failure if the given field value doesn't match the RFC 822 specification. In RFC 822 the format of valid email addresses is defined. This check routine is somewhat better than email, the only disadvantage is, that some working email addresses don't fit to RFC 822. So if you get problems try using the <email> routine.

I copied this routine from http://www.cpan.org/authors/Tom_Christiansen/scripts/ckaddr.gz!

date

Returns invalid if the field value seems to be incompatible to common date formats or the date doesn't exist in the Gregorian calendar. The following formats are allowed:

dd.mm.yyyy dd-mm-yyyy dd/mm/yyyy yyyy-mm-dd yyyy/mm/dd yyyy.mm.dd

The check_date method of the Date::Pcalc package is used to prove the dates existence.

digitonly

... returns invalid if the value doesn't match '[0-9]*'.

fmatch

... requires the special variable fmatch. This variable must contain the name of another field. The value of this field is read in and compared with the current value, doesn't match is returned if this fails.

When using the same fields several times, you must also define ROWNUM, this must start with 1 increased by one whenever the field names are repeated.

Note: When you defined several tables, you must reference other fields with tablename.fieldname!

regex

... requires the special variable regex, it must contain a valid regular expression. If the value doesn't match this regex, invalid is returned.

WRITING A CHECK ROUTINE

Design

In general, a check routine has the following structure:

  sub mycheck {
    my($value,$name,$self) = @_;
    #some lines of code#
    return gettext('My ErrorMessage');
  }

$value contains the submitted field value. $name contains the fields name. $self contains a reference to the FormEngine object.

Note: you can define the error message by yourself with the variable errmsg!

Install

If your routine does a general job, you can make it part of FormEngine. Therefore just add the routine to this file and refer to it from Config.pm. Please send me such routines.

ERROR MESSAGE TRANSLATIONS

The translations of the error messages are stored in FormEngine.po files. Calling msgfmt translates these in FormEngine.mo files. You must store these FormEngine.mo files in your locale directory, this should be /usr/share/locale, if it isn't, you must change the value of $textdomain in Config.pm.

Provided that a translation for yourlanguage exists, you can call setlocale(LC_MESSAGES, 'yourlanguage') in your script to have the FormEngine error message in yourlanguage.