Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Form Processing

by moritz (Cardinal)
on Mar 25, 2009 at 10:03 UTC ( [id://753082]=note: print w/replies, xml ) Need Help??


in reply to Form Processing

If it is done on internal representation - then how errors are supposed to be propagated to the HTML generator (which works on the key value pairs)?

By having a bi-directional mapping between the internal representation and the key-values pairs

How to interface with specialized data validating libraries?

Callbacks might be a solution

When form should be saved to the database? Obviously only when it has valid parameters - but some people also check the HTTP method and other things.

IMHO saving things to a database is not job of the form processor. It could create objects that can be stored into the database with a single method call, but it shouldn't do it - that's the job of the controlling method that called the form processor in the first place.

When values should be loaded from the database?

Same answer as above.

IMHO a form processor shouldn't talk to the database at all, at least not directly. For example the callbacks that validate input data could talk to the database, but having a form processor do that seems like over stretching its task.

Could it be that you have a full CRUD framework in mind, not just a form processor?

Replies are listed 'Best First'.
Re^2: Form Processing
by zby (Vicar) on Mar 25, 2009 at 10:31 UTC
    Ad. 'talking to the database'. I think I partially agree - and indeed I've wrote DBIx::Class::ResultSet::RecursiveUpdate exactly for the task of saving the data that I get from form processors (originally for FormFu, later Rose, and now I think about HTML::FormHandler, thanks to having it separated I can change the form processors quite easily). So the form only generates an update hash (or a more complex structure of hashes and arrays) and it is saved to the db by this specialized module. But still on the form processor there is always that ->save_to_db (or ->process) method which asks RecursiveUpdate to do the saving. It is just convenient.

    And in the other direction - it is the same thing, you need to walk all the form nodes and convert the internal objects into the field values - what else could be better suited for that task than the form processor itself?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found