Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

I need a help! regarding with SELECT html with Perl

by huchister (Acolyte)
on Sep 18, 2012 at 19:29 UTC ( #994339=perlquestion: print w/replies, xml ) Need Help??
huchister has asked for the wisdom of the Perl Monks concerning the following question:

I am relatively new to perl, so Please help! perl monk!

I am working on this 'Approve user uploaded pictures' before let it go live, However I also like to move them into each specific gallery while I approve it at the same time

I have to use SELECT HTML array and send selected value(gallery id) as Perl parameter. Now the problem is I am not only sending one picture. I am sending multiple picture into multiple gallery. (can be selected), but I am stuck on PERL function where I have to set each selected value into different item

sub accpending { my $self = shift; #reads the checked list from pending function. my @pids = param('list'); my @selectedparam = param('gallery'); my $i = 0; foreach my $pid (@pids) { my ( $pxml, $pob ) = @$self{'pxml','pob'}; my $item = $pob->find_node( $pxml->{'xml'}, 'item', id => $pid ); # points to gallery my $chosengallery = @selectedparam[$i]; # print "item: $item\n"; #if item cannot be found in pending list, prints this. # if( !$item ) { # WCM::Basic::doheader($self); # print "Item to approve is already gone"; # return; # } # recevie the selected gallery for addtogallery # from approve() function $item->{'_change'} = 1; # change gallery according from seelcted param. $item->{'gallery'} = {value => $chosengallery}; my $node = $self->addtogallery($item, 0); $self->genthumbs ($node); #we want to save it at iob real list to make sure we have the item + in the gallery. $self->{'iob'}->save(); #make sure to delete node from pob, since file has been moved to a +pproval list already. we dont want this picture to keep in our system +. #save the newly updated pending list. #comment out if you want to temporary disable moving from pendingl +ist. #$pob->del_node( $pxml->{'xml'}, 'item', id => $pid ); $pob->save(); $i++; } }

Here is the HTML section.

#new galleryops for choosing gallery my $dgallery = xval $item->{'gallery'}; my $galleryops = $self->gengalleryops( $dgallery ); my $className = ( $i % 2 ) ? 'row t_list' : 'row t_list_alt'; $i++; # List pending images along with checked list $ret .= " <tr class='$className'> <td onmouseout='showPicture(\"$file\",0, \"$path\")' + onmouseover='showPicture(\"$file\",1, \"$path\")'>$file</td> <td onmouseout='showPicture(\"$file\",0, \"$path\")' + onmouseover='showPicture(\"$file\",1, \"$path\")'>$shorttitle</td> <td id='$file'></td> <td>$date</td> <td onmouseout='showPicture(\"$file\",0, \"$path\")' + onmouseover='showPicture(\"$file\",1, \"$path\")'>$desc</td> <td> <select id='curgal' onchange='showgalfields()' name='g +allery[]'> <option value='-1'>Select One</option>$galleryops </select> </td> <td onmouseout='showPicture(\"$file\",0, \"$path\")' + onmouseover='showPicture(\"$file\",1, \"$path\")'>&nbsp;</td> <td><input type='checkbox' name='list' value='$id' s +tyle='float: right;'></td> </tr>"; }

Notice only checked list value need to get approval. But at the same time, it needs to move into USER SELECTED GALLERY

I also need to set if statement if user didn't SELECT gallery, dont approve it

So, Basically I am stuck where I have to make while statement to run array simutaneously, and I need to make if statement to make sure ONLY THE CHECKED VALUE gets approval.


Replies are listed 'Best First'.
Re: I need a help! regarding with SELECT html with Perl
by GrandFather (Sage) on Sep 20, 2012 at 21:47 UTC

    Take a look at HTML::Template. It has the potential to make your life much easier. Consider:

    use strict; use warnings; use HTML::Template qw(); my $tmplStr = <<TMPL; <tr class='<TMPL_VAR name="className">'> <TMPL_LOOP name="pictures"> <td onmouseout='showPicture("<TMPL_VAR +name="file">",0, "<TMPL_VAR name="path">")' onmouseover='showPicture("<TMPL_VAR name="file">",1, "<TMPL_VA +R name="path">")' ><TMPL_VAR name="file"></td> </TMPL_LOOP></tr> TMPL my $tmpl = HTML::Template->new(scalarRef => \$tmplStr); my @pictures = ( {file => 'wibble.jpg', path => '/here/there/everywhere'} +, {file => 'wobble.jpg', path => '/here/there/everywhere'} +, {file => 'floop.jpg', path => '/here/there/elsewhere'}, ); $tmpl->param( className => 'pinkAsAnything', pictures => \@pictures, ); print $tmpl->output();


    <tr class='pinkAsAnything'> <td onmouseout='showPicture("wibble.jpg",0, "/here/there/everywher +e")' onmouseover='showPicture("wibble.jpg",1, "/here/there/everywhe +re")' >wibble.jpg</td> <td onmouseout='showPicture("wobble.jpg",0, "/here/there/everywher +e")' onmouseover='showPicture("wobble.jpg",1, "/here/there/everywhe +re")' >wobble.jpg</td> <td onmouseout='showPicture("floop.jpg",0, "/here/there/elsewhere" +)' onmouseover='showPicture("floop.jpg",1, "/here/there/elsewhere +")' >floop.jpg</td> </tr>

    which isn't the answer you thought you were looking for, but should head you in a useful direction. Note that you can load the template HTML from a file instead of a string so the HTML becomes independent of your script to make maintnance of both clearer and easier.

    True laziness is hard work
      Thanks, I didn't solved problem this way, but looks a lot lot easier than what I have wrote. I shall take a look at template also. However I made a function that receive array of selected value, while loop to sort out which one to sent or not. Have nice day!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994339]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2017-07-20 23:28 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (316 votes). Check out past polls.