[ic] form and set

Kevin Walsh interchange-users@icdevgroup.org
Tue Jun 25 01:43:01 2002


> I've setup a new admin page to add qualities to a product.
> He re is the code:
>
> <FORM ACTION="" METHOD=POST NAME="main">
> <INPUT type=hidden NAME="item_id" VALUE="[cgi item_id]">
> <INPUT TYPE=hidden NAME=mv_todo VALUE="return">
> 
> [loop list="1..10" ranges=1]
> 				<select name="genres" size="5">
> 				[query list=1 prefix=inner sql="SELECT *
>                                   FROM genres
>                                   "]
>      				<option value="[inner-param genre_id]"
> 				>[inner-param genre_nom]
> 				[/query]
>                                  </select>
> [/loop]
> 
> [seti name="OK"]
>     [perl tables=produits_genres]
>     my @genres = split /\0/, $CGI->{genres};
>     my @ids = split /\0/, $CGI->{ids};
>     my $sku = $CGI->{item_id};
>     my $i = 0;
>     my $numelements = scalar (@genres);
>     $Tag->query({sql => "delete from produits_genres where sku = '$sku'"});
>     while ( $i < $numelements)
>     {
>     $Tag->query({sql => "insert into produits_genres (genre_id,sku) 
> values ('@genres[$i]','$sku')"});
>     $i++;
>     }
>     return;
>     [/perl]
> [/seti]
> 
> <input type="submit" name="mv_check" value="OK">
> </form>
> 
> I don't understand why the code between the [seti] tag is execute when 
> the page loads and not only when  the "OK" button is click.
> 
It's interpolated at page-parse-time, rather than executed as a callback
because you used [seti] instead of [set].  [seti] is a shorthand version
of [set interpolate=1].

Other notes, while I'm here:

1) You will need to specify a form action, rather than leaving it as
   an empty string, like this:

       <form action="[process-target]" method="POST">

3) A "hidden" mv_nextpage would be good too:

       <input type="hidden" name="mv_nextpage" value="somepage">

   "somepage" could be "@@MV_PAGE@@", or wherever.

2) You should pass the session ID as part of the form POST data for
   the benefit of users who disable cookie support:

       <input type="hidden" name="mv_session_id" value="[data session id]">

4) Your Perl is using @genres[$i], whereas $genres[$i] would be better.

5) I hope that none of your "genres" contains a quote (') character.
   Same with the SKU.

I'm sure you've had enough of my nit-picking, so I'll leave it there. :-)

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin@cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/