Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

RFC: Data::FormValidator enhancement proposal

by markjugg (Curate)
on Feb 12, 2002 at 15:48 UTC ( [id://144887]=perlmeditation: print w/replies, xml ) Need Help??

Hello,

I'm working on adding an addition to the Data::FormValidator module and want to get your feedback on it.

The primary issue I'm addressing at the moment could be summarized as

"missing optional fields disappear"

Here's a more detailed explanation:

If a field is marked as optional in the validation profile, and is present but empty in the input hash, the field does not appear anywhere in the resulting output-- it's not marked as valid, missing, invalid or unknown.

Most of the time this doesn't matter, but there is important case that it does: If you are using the profile for an "update" web form, and the initial data set contains some text, but the user removes it, the field does not appear in the %valid hash returned, so if you pass that directly to DBIx::Abstract to update a database for example, that field won't get updated to be empty in the database. This can be worked around with some additional perl, but it's annoying to have to do it every time.

What I plan to do is to add an option that allows missing optional field to be classified as valid. This actually seems like a more intelligent default behavior to me, although I'm hesitant to make this a true default to avoid breaking existing applications that might rely on this subtle distinction.

Here's the interface I have in mind.

Each input specification would support an additional key:

# can you think of a shorter way to express this? missing_optional_fields_are_valid => 1

This would default to zero, the old behavior, and set to a true value to get the new behavior.

Any suggestions on alternate ways to make this interface change this before I add it into the module?

Thanks,

-mark

update: This has now been added to Data::FormValidator 1.8. Thanks for your feedback!

Replies are listed 'Best First'.
Re: RFC: Data::FormValidator enhancement proposal
by AidanLee (Chaplain) on Feb 12, 2002 at 21:41 UTC

    I think a flag is definitely the way to go. for something pithier, though, you might try

    missing_optionals_valid => 1 #or, depending on your style missingOptionals_valid => 1
      Thanks for the feedback AidanLee. I think I'll go with your first suggestion.

      -mark

Re: RFC: Data::FormValidator enhancement proposal
by dpatrick (Scribe) on Feb 13, 2002 at 19:14 UTC
    I agree, with that the shorter flag metioned above would be the best. However, I can't think of any cases where you would want empty fields to disappear as that would require extra code on the server side to make note that those fields existed in the first place. Kudos for this module, we could use something like this at the company that I work for!

    dpatrick
    - I think scsh is cool.
    Open Sourceror, Perlmonk
    http://perlmonk.org/~dpatrick
Re: RFC: Data::FormValidator enhancement proposal
by mattr (Curate) on Feb 16, 2002 at 18:08 UTC
    Definitely useful. If it wouldn't seem to break already deployed code, I'd say make default that the options don't disappear. I just had someone come to me with that problem the other day, and I think someone on perlmonks too. Must hit every cgi programmer once (or more for some of us:)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://144887]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found