Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello.

I'm making a little script that retrieves input from a HTML form.

Depending on how many existing records there are, determines the amount of input fields for the end user to edit.

Im not sure how to retrieve those certain input fields since theres no definitive # of records to edit. I have already finished the part that prints out the HTML form which sorta goes as:

<input type="text" name="text1" value="Existing Data"> <input type="text" name="text2" value="Existing Data 2"> <input type="text" name="text78" value="Existing Data 78"> <input type="text" name="text3" value="Existing Data 3">
What I need to do is to have my script retrieve these values.

Since the name of the text field can awlays vary, I figured I need to retrieve a list of values with the parameter name to contain the word "text". Still not that good with Perl, so any help will be great :)

Thanks

Replies are listed 'Best First'.
Re: How to retrieve certain Form Input
by imp (Priest) on Jul 26, 2006 at 21:32 UTC
    #!/usr/bin/perl use strict; use warnings; use CGI; my $cgi = CGI->new(); # Get a list of all parameters my @params = $cgi->param(); # Get a list of parameters that are named 'text' followed by a number my @text_fields = grep /^text\d+$/, @params; #Output the http header print "Content-type: text/html\n\n"; for my $param (@text_fields) { printf "%10s = %s<br>\n", $param, $cgi->param($param); }
Re: How to retrieve certain Form Input
by GrandFather (Saint) on Jul 26, 2006 at 21:32 UTC

    You should take a look at HTML::TreeBuilder and at the look_down method. That returns a list of elements that match some search criteria.


    DWIM is Perl's answer to Gödel