This is certainly something that could be useful, and I was trying to work out how to do something very similar quite recently.

You might want to think a bit about how to get a useful separation of concepts: in my case, I already have a bunch of field definition objects (constructed from the same data as was used to create the table in the first place), so I hope you'd provide a mechanism (by subclassing or with a direct hook) to bypass the "fetch and parse the describe table info".

Another issue is the level of control the caller has over the output: she might want to choose, for example, whether a particular varchar field should be presented as a text input field or as a textarea, and might also want to supply the visual dimensions of the result. I haven't yet come up with a clean way of passing such information around.

If you allow such levels of control, you'll probably find (as I did) that you need to incorporate both the field name and the display type into the parameter name, so that you know how to decode the parameters when the form is submitted. This also allowed me, for example, to invent a pseudo input-type of "date" and present it as 3 drop-downs for day/month/year instead of being forced to present it as a string.

Hugo

In reply to Re: Automatically generating html form fields from a DBI handle by hv
in thread Automatically generating html form fields from a DBI handle by Your Mother

Title:
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, details, 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, summary, 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.