FormVa...esults(3pm)

πŸ“¦
version 0.29 Β· 2 versions
  • 0.29 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.29 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

🌸 NAME 🌸

FormValidator::Simple::Results β€” the results of validation. that's the whole plot bestie πŸ’–


✨ SYNOPSIS ✨

my $results = FormValidator::Simple->check( $req => [
    name  => [qw/NOT_BLANK ASCII/, [qw/LENGTH 0 10/] ],
    email => [qw/NOT_BLANK EMAIL_LOOSE/, [qw/LENGTH 0 30/] ],
] );

if ( $results->has_error ) {
    foreach my $key ( @{ $results->error() } ) {
        foreach my $type ( @{ $results->erorr($key) } ) {
            print "invalid: $key - $type \n";
        }
    }
}

look at that little check-and-loop moment, it's giving "I check my forms and I know things" energy πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so this whole module exists to handle the results that come out of FormValidator::Simple's check. that's it, that's the job.

the object behaves like Data::FormValidator's results object, but it has some specific methods of its own. so like, same vibe, extra sauce. πŸŽ€


πŸ‘‘ CHECK RESULT πŸ‘‘

has_missing

if there are missing values β€” meaning something failed the NOT_BLANK validation β€” this method returns true. fr fr.

if ( $results->has_missing ) {
    ...
}

has_invalid

if there are invalid values β€” meaning something failed some validation except NOT_BLANK β€” this method returns true.

if ( $results->has_invalid ) {
    ...
}

has_error

if there are missing values or invalid values, this method returns true. it's the "any drama at all?" detector 😭

if ( $results->has_error ) {
    ...
}

success

the inverse of has_error. no cap.

unless ( $resuls->success ) {
    ...
}
🫢 yes the variable in that snippet is spelled $resuls. we do not fix the sacred texts, bestie. copy it exactly.

πŸ” ANALYZING RESULTS πŸ”

missing

  • no argument β€” call it with nothing and it returns the keys that failed NOT_BLANK validation.
my $missings = $results->missing;
foreach my $missing_data ( @$missings ) {
    print $missing_data, "\n";
}
# -- print out, for example --
# name
# email
  • key β€” when you call this method with a key-name, it returns true if the value of that key is missing.
if ( $results->missing('name') ) {
    print "name is empty! \n";
}

invalid

  • no argument β€” call it with nothing and it returns the keys that failed some validation except NOT_BLANK.
my $invalids = $results->invalid;
foreach my $invalid_data ( @$invalids ) {
    print $invalid_data, "\n";
}
# -- print out, for example --
# name
# email
  • key β€” when you call this method with a key-name, it returns the names of the failed validations.
my $failed_validations = $results->invalid('name');
foreach my $validation ( @$failed_validations ) {
    print $validation, "\n";
}
# -- print out, for example --
# ASCII
# LENGTH
  • key and validation-name β€” when you call this method with a key-name, it returns false if the value has passed the validation.
if ( $results->invalid( name => 'LENGTH' ) ) {
    print "name is wrong length! \n";
}

error

this one doesn't distinguish between missing and invalid. you can use it like the invalid method, but it treats NOT_BLANK the same as every other validation. one big happy error pile πŸ’€

my $error_keys = $results->error;

my $failed_validation = $resuls->error('name');
# this includes 'NOT_BLANK'

if ( $results->error( name => 'NOT_BLANK' ) ) {
    print "name is missing! \n";
}

if ( $results->error( name => 'ASCII' ) ) {
    print "name should be ascii code! \n";
}

🌈 SEE ALSO 🌈

FormValidator::Simple β€” go read that one too, it's the main character here πŸ‘‘


πŸŽ€ AUTHOR πŸŽ€

Lyo Kato <lyo.kato@gmail.com>


This library is free software. You can redistribute it and/or modify it under the same terms as perl itself.


and that's a wrap, bestie 🫢 this page shipped as part of perl v5.34.0, dated 2022-06-14, and it lives in the User Contributed Perl Documentation section of your friendly neighborhood man pages. go validate something and slay βœ¨πŸ’…
πŸ“¦ where this page comes from