Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This is a meditation on processing data from HTML forms. There is a page at the Perl 5 wiki on that subject - it is a more practical list of available form processing libraries, here I wanted to ponder a bit more theoretically on that subject (and perhaps later update that other page).

What form processors do:

  1. Parsing the CGI parameters and constructing internal version of them. This might be basic (only parsing), through constructing a simple data structure (for hierarchical params - like param.subparam etc) to constructing objects (for dates).
  2. Validating
  3. Saving the values to the persistance layer (database)
  4. Loading values from the persistance layer for point 5
  5. Generating HTML (with error indicators etc).
Not all form processors need to do all of those parts (many don't generated HTML). And there are questions:
  1. Should the HTML be generated? I think it is useful as a 'first stage' approach. The logic of adding the error messages and inserting appriopriate error CSS classes is quite complicated so this saves a lot of work. But there should be also left a path for upgrading to using external form templates with the library - so that later, when the project grows the designers can use some more fancy constructs.
  2. Should validation be done on the internal representation (objects) or on the key value pairs from the first parsing? 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)?
  3. How to interface with specialized data validating libraries?
  4. 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.
  5. When values should be loaded from the database? Only if form is not submitted - but I also like to pass values to a form from a link - so I would like if it would not overwrite it with values from the db.

In reply to Form Processing by zby

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (3)
    As of 2020-10-25 00:27 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (248 votes). Check out past polls.