in reply to Re: process multiple rows from form
in thread process multiple rows from form

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.

Replies are listed 'Best First'.
Re^3: process multiple rows from form
by eric256 (Parson) on Sep 27, 2005 at 14:59 UTC

    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