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

I am building a webpage where the user should be able to update several rows at the same time. The rows are created dynamically into an html form from my database.

The input fields on every row will get the same name, I will use an id attribute with an objectid value to make the rows unique.

However, when the form is submitted I want to update my database with the corresponding data from my form. How do I process a form like this or how do I read the id attribute with the CGI object.

I know I could append the objectid to all my input fields but there must be a much cleaner solution.

Replies are listed 'Best First'.
Re: process multiple rows from form
by Skeeve (Parson) on Sep 26, 2005 at 17:24 UTC
    Maybe I simply don't understand what you want to achieve. It looks to me like you got several input fields on a web page, all with the same name, but with different id. Now you want to read the submitted form in your CGI and want to get the id, not the name.

    AFAIK the id is not submitted, so no way to read it. You will have to make the name the id (or append the id to the name) in order to get that info.

    $\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print
      here is a small example:
      <form name="myform" method="post" action="index.cgi"> <input type="hidden" name="rm" value="doSomething"> <TMPL_LOOP NAME="LOOP_DATA"> <input name="name<TMPL_VAR NAME=objectid>" value="<TMPL_VAR NAME=compu +ter>"> <input name="price<TMPL_VAR NAME=objectid>" " value="<TMPL_VAR NAME=pr +ice>">"> <input name="qty<TMPL_VAR NAME=objectid>" " value="<TMPL_VAR NAME=qty> +">"> </TMPL> </form>
      There must be a cleaner solution to process a form like this than the above solution where I append the objectid to the input name attribute. I thought I could use the id attribute somehow but apparently not.

        I do something similar. Generaly I throw a _ in the name so its 1_price. Then loop over it spliting them out. Probably some easier way to do it, but I've sued something similar to the following.

        my $ids = {}; my @params = $cgi->param(); foreach my $param ( @params ) { my ($id, $field) = $param =~ /^(\d+)_(.*)$/; $ids->{$id}->{$field} = $cgi->param($param); }

        Depending on the values you could get and how you want to handle them you might need to check for the lenght of the return value. YMMV


        ___________
        Eric Hodges