HTML::...traint(3pm)
π HTML::FormFu::Constraint β the manual, but make it slay π
okay bestie, you found the page for HTML::FormFu::Constraint (the one and only <pink>HTML::...traint(3pm)</pink>, filed under User Contributed Perl Documentation) and honestly? it's giving main character energy for your form validation era. it's a Perl module, it's version 2.07, and it's here to Constrain User Input. yes queen, constrain it. β¨
πΈ NAME πΈ
HTML::FormFu::Constraint β Constrain User Input π
β¨ VERSION β¨
version 2.07 π
π¦ SYNOPSIS π¦
here's the whole vibe, verbatim, no notes:
---
elements:
- type: Text
name: foo
constraints:
- type: Length
min: 8
when:
field: bar
values: [ 1, 3, 5 ]
- type: Text
name: bar
constraints:
- Integer
- Required
constraints:
- SingleValue
look at that little when block doing its thing. periodt. π₯
π DESCRIPTION π
okay so when user input comes in, it gets processed in this exact order, no skipping the line:
- Filters
- Constraints
- Inflators
- Validators
- Transformers
(if you want the deep lore, go read "FORM LOGIC AND VALIDATION" in HTML::FormFu.) π
so, "constraints" in HTML::FormFu can be called on any form, block element (and yes, that includes fieldsets) or field element. flexible queen.
- If you call it on a field element, you should not pass a
nameargument. no name, bestie, don't do it. - If you call it on a form or block element and you don't give a
nameargument, then a brand new constraint gets created for and added to every single field on that form or block. every. single. one. π
and yeah β see "FORM LOGIC AND VALIDATION" in HTML::FormFu for further details, because apparently twice wasn't enough. iconic of it tbh.
π METHODS π
π type
Returns the type argument originally used to create the constraint. it remembers where it came from. nostalgic.
π not
If true, it inverts the results of the constraint β so input that would otherwise fail will pass, and vise-versa. chaotic. love that for you.
β οΈ heads up: this value is ignored by some constraints β go check the docs for individual constraints for the deets. don't come for me, come for them.
π only_on_reps
Arguments: \@repeatable_count
For constraints added to fields within a Repeatable element: if only_on_reps is set, the constraint will only run for fields whose repeatable_count matches one of these set values. very picky, very demure. π
π Not available for the constraints listed in "Unsupported Constraints" in HTML::FormFu::Element::Repeatable.
π message
Arguments: $string
Sets the message that gets displayed if the constraint fails. your custom little "no β€οΈ" text.
π message_xml
Arguments: $string
A variant of message which makes sure the value won't be XML-escaped. raw, unfiltered.
π message_loc
Arguments: $string
A variant of message which uses localize to create the message. multilingual slay π
π localize_args
Provide arguments that should be passed to localize to replace "[_1]", "[_2]", etc. in the localized string. fill in the blanks, bestie.
π force_errors
See "force_errors" in HTML::FormFu for details. (go, go read it, i'll wait π«Ά)
π parent
Returns the field object that the constraint is associated with. its parent. its origin story.
π form
Returns the HTML::FormFu object that the constraint's field is attached to.
π name
Shorthand for $constraint->parent->name. short king.
π when
Defines a condition for the constraint. Only when the condition is fulfilled will the constraint be applied. conditional queen π
This method expects a hashref.
The field or callback must be supplied β all other fields are optional.
If value or values is not supplied, the constraint will pass if the named field's value is true.
The following keys are supported:
fieldβ Nested-name of form field that shall be checked against β ifwhen->{value}is set, thewhencondition passes if the named field's value matches that, otherwise thewhencondition passes if the named field's value is true.fieldsβ Array-ref of nested-names that shall be checked. Thewhencondition passes if all named-fields' values pass, using the same rules asfieldabove.any_fieldβ Array-ref of nested-names that shall be checked. Thewhencondition passes if any named-fields' values pass, using the same rules asfieldabove.valueβ Expected value in the form field 'field'valuesβ Array of multiple values, one must match to fulfill the conditionnotβ Inverts the when condition β value(s) must not matchcallbackβ A callback subroutine-reference or fully resolved subroutine name can be supplied to perform complex checks. An hashref of all parameters is passed to the callback sub. In this case all other keys are ignored, includingnot. You need to return a true value for the constraint to be applied or a false value to not apply it.
The callback subroutine receives 2 arguments:
$params(hashref of all submitted parameters)$constraint(the Constraint object)
π§ͺ EXPERIMENTAL METHODS π§ͺ
β fetch_error_message
Return value: $string
Attempts to return the error message that would be used if this constraint generated an error.
This will generally be correct for simple constraints with a fixed message or which use a placeholder from a known value, such as min in HTML::FormFu::Constraint::Min.
π this will generally "not" return the correct message for constraints which useothersinHTML::FormFu::Role::Constraint::Othersβ because the field with an error is not known without actually fully processing a form submission. it's a mystery until you commit, bestie.
π CORE CONSTRAINTS π
the whole squad, in order:
HTML::FormFu::Constraint::AllOrNoneHTML::FormFu::Constraint::ASCIIHTML::FormFu::Constraint::AutoSetHTML::FormFu::Constraint::BoolHTML::FormFu::Constraint::CallbackHTML::FormFu::Constraint::CallbackOnceHTML::FormFu::Constraint::DateTimeHTML::FormFu::Constraint::DependOnHTML::FormFu::Constraint::EmailHTML::FormFu::Constraint::EqualHTML::FormFu::Constraint::FileHTML::FormFu::Constraint::File::MIMEHTML::FormFu::Constraint::File::MaxSizeHTML::FormFu::Constraint::File::MinSizeHTML::FormFu::Constraint::File::SizeHTML::FormFu::Constraint::IntegerHTML::FormFu::Constraint::JSONHTML::FormFu::Constraint::LengthHTML::FormFu::Constraint::MaxLengthHTML::FormFu::Constraint::MaxRangeHTML::FormFu::Constraint::MinLengthHTML::FormFu::Constraint::MinRangeHTML::FormFu::Constraint::MinMaxFieldsHTML::FormFu::Constraint::NumberHTML::FormFu::Constraint::PrintableHTML::FormFu::Constraint::RangeHTML::FormFu::Constraint::RegexHTML::FormFu::Constraint::RequiredHTML::FormFu::Constraint::SetHTML::FormFu::Constraint::SingleValueHTML::FormFu::Constraint::Word
π NON-CORE CONSTRAINTS AVAILABLE ON CPAN π
the guest star, popping in from CPAN:
HTML::FormFu::Constraint::reCAPTCHA
π CAVEATS π
See "Unsupported Constraints" in HTML::FormFu::Element::Repeatable for the list of constraints that won't work within HTML::FormFu::Element::Repeatable. read it before you fight it, fr fr.
πΈ AUTHOR πΈ
Carl Franks, "cfranks@cpan.org"
Based on the original source code of HTML::Widget::Constraint, by Sebastian Riedel, "sri@oook.de". giving credit where credit is due π«Ά
π LICENSE π
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. free as in bestie. π
π¦ AUTHOR (again, yes really) π¦
Carl Franks <cpan@fireartist.com>
β¨ COPYRIGHT AND LICENSE β¨
This software is copyright (c) 2018 by Carl Franks.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay that's the whole page, no notes, we ate π and for the cute sign-off: this absolute icon was generated on 2019-01-12 running under perl v5.28.1, so if your perl is newer than that, congrats bestie, you're on your own timeline ππΈπ¦β¨π
π¦ where this page comes from
- debian bookworm: libhtml-formfu-perl 2.07000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libhtml-formfu-perl 2.07000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhtml-formfu-perl 2.07000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms