Hi Monks,

I’m writing a web application in Perl. It has a form containing contact information, the code for which is currently laid out something like this:

$form_htm = <<EOF <input value="$in{firstname}" name="firstname"> <input value="$in{surname}" name="surname"> ...etc... EOF
Later on I print $form_htm (amongst other things) to display the webpage.

The above is working for me, and the fields are interpolated as expected.
However, I’d like different organisations who use this application to be able to have a different layout for their fields.  Some fields won’t apply to some organisations, and some organisations will want different sizes (on the webpage) for fields than others.
So, I thought I’d store the HTML for the form in a database (different versions in different records for different organizations).
But because the HTML is not stored in the script, the fields (like $in{firstname}) are not interpolated, so the variable names themselves are ending up on the webpage, (which is not quite the look I’m after).

Any recommendations on how I should get these variables to be evaluated in this context? (First thing that came to mind is eval(), but that seems aimed at evaluating expressions, not variables mixed in with a lot of other text.)
Or can you suggest a better approach which would allow different organisations to have different form layouts?

Edit: I have also posted this question on StackOverflow, but would like to get other opinions.

Thanks.
tel2


In reply to Interpolation of variables in stored HTML by tel2

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.