According to the text
--#--
Text fields are the most prevalent in the usual form, and
relatively easy to handle, so let's start there. A text
input boxe can be easily identified by the string
≶input type="text" ... It's tempting to write a simple
regex that recognizes the field name and stuffs the data into
a value parameter to this tag.
$val = $query->param($key);
$html_content =~ s/(
What's good about this code? Using /si it matches across line
breaks, and it's case-insensitive. Also, using ? makes the
quote marks optional. It will match
<input type="TEXT" name="First_name" size="25">, but it won't
match <input name="First_name" type="TEXT" size="25">
You COULD require that all HTML form tags MUST have the type parameter
first, immediately followed by the name parameter. But that's too easy,
and besides, it's prone to breaking. What if you (or another maintainer)
later edit the HTML? If you're not familiar with the code, or have
forgotten about it, you may spend the better part of an hour discovering
why it's broken.
Much better to make the code flexible and robust. Start by pulling only
the text fields out of the parameter list. How? Not by a regex alone.
Use Perl's split function to get at each <input individually.
# make an array to store the fields
my @t = ();
my @text_fields = split(/
You split the whole file into parts, each -- except the first --
beginning with an <input tag. Somewhere in that tag is
a name field. If there's also a text type field, grab the
name by parenthesizing it and back-referencing it.