[html-formfu] some questions

Mario Minati mario.minati at googlemail.com
Fri Sep 7 20:38:29 GMT 2007

On Friday 07 September 2007 21:03:14 Jim Spath wrote:
> Mario Minati wrote:
> > On Friday 07 September 2007 17:10:11 Jim Spath wrote:
> >> I'm new to HTML::FormFu (never used HTML::Widget) either, and have a
> >> couple of questions:
> >>
> >> The first one is how to easily utilize values which have been altered by
> >> FormFu's validation.  An example would be the TrimEdges filter.  If a
> >> user enters a value like "  foo  " and we need to redisplay the form, I
> >> would like the prefilled value to be "foo".
> >
> > The usual behaviour is to give the data back to the user exactly the way
> > he wrote it, returning preprocessed values may confuse him.
> > That's also the default behaviour of FormFu.
> >
> > I'm not sure if that can be changed. Maybe anyone else can help out.
> Hm, I think we can learn to work with the current behavior.
> >> Secondly, if I want to add a complex validation routine, like checking
> >> to see if a US address is USPS deliverable, is this best done as a
> >> callback constraint, or a validator?  If validator, can someone point me
> >> to an example of a validator?  The only useful information on validators
> >> seemed to be t/validator.t
> >
> > Best place would be a validator, regarding to the docs:
> > http://search.cpan.org/~cfranks/HTML-FormFu-0.01003/lib/HTML/FormFu.pm#FO
> >RM_LOGIC_AND_VALIDATION Also from my practice, validator is the right
> > state during the form processing.
> > I think the best way to create your own validator is to look in the
> > source code in svn. There is jet no howto or other examples out here, but
> > it's quite easy (tm). Just have a look in the source of the
> > callback-validator.
> Ok, I will try implementing the address check as a validator, but I
> guess I'm still a little unclear on when a given check should be run as
> a constraint vs a validator.  I have read the docs, but it doesn't seem
> to be well defined.

From the docs:

Constraints are intended for low-level validation of values, such as "is this 
value within bounds" or "is this a valid email address".

Validators allow for a more complex validation than Constraints. Validators 
can be sure that all values have successfully passed all Constraints and have 
been successfully passed through all Inflators. It is expected that most 
Validators will be application-specific, and so each will be implemented as a 
seperate class written by the HTML::FormFu user.

I think your goal is not a low level thing.

> Also, the address validation we are using can auto-correct addresses in
> certain cases.  Is it possible for a validator (or a constraint) to
> modify parameter values if necessary?

If I recall right you have to overwrite the process function in the class you 
derive from HTML::FormFu::Validator. The process function gets the param as 
parameter. Maybe you have to use Dumper a little to find out the 

One thing I don't understand:
Do you want the user to see which changes you make?
Then you must set the error flag to force a redisplay.


More information about the HTML-FormFu mailing list