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

I like to get user selection from the browser via checkboxes. The problem is that I have 1000s of item and I can display only 20 at a time. So after user selects the item, I like to present next screen to select other items. When user is done selecting all items, I like to process those items. My item ID are 32 digits long. What methods I use to retain selections of user across different screen. I am running apache, but not mod_perl.

  • Comment on Selecting Items Across multiple screen.

Replies are listed 'Best First'.
•Re: Selecting Items Across multiple screen.
by merlyn (Sage) on Apr 23, 2004 at 16:19 UTC
    Aiyeee! What is that, some sort of torture test for your user/customer?

    From human-interface perspective, for example, I dread having to change my TVGuide.com settings, because they present to me a list of about 800 channels that I may or may not subscribe to... initially all checked. I then have to go down and deselect all the pay-per-view channels, and the spanish channels, and a few others that I actually don't get.

    And the problem is that each one of these selections requires an incredible eye-hand coordination... "move mouse, click, darn missed, move mouse some more, click again". Over and over and over again.

    Please, for the love of humanity, provide some interface other than checkboxes! How about a multiple-select scrolling box, so at least I could drag through regions (or start/end click) to toggle them, provided my browser is smart enough?

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Good insight! I cannot do the scrolling as this is very subjective and they are actually result of the browse/search, displaying very specific items and it changes on regular base. So checking item is subject issue rather than objective issue. -- Next screen selection may come from variety of point. So hidden fields will not work. --It seems that Cookies with CGI::Session etc would be the best way to go.
Re: Selecting Items Across multiple screen.
by davido (Cardinal) on Apr 23, 2004 at 16:07 UTC
    You can pass the selected items on to the next "screen" via hidden HTML fields. If they're mission critical, you may need to encrypt them first in some way.

    You can also store your user's temporary ID in a cookie and keep the selections in a temp file. Or pass the temporary ID along in a hidden field and retain the selections in a temp file.

    Those are just a few options for maintaining state in a stateless environment.


    Dave

Re: Selecting Items Across multiple screen.
by Ovid (Cardinal) on Apr 23, 2004 at 16:11 UTC

    Without seeing code and understanding your business needs, it's tough to say what would be best for you, but basically you need to maintain state either client side or server side. Each has advantages and disadvantage.

    To maintain state on the client side, simply put the selected items into hidden fields:

    <form ...> <input type="hidden" name="product_id" value="product_22" /> <input type="hidden" name="product_id" value="product_11" /> <input type="hidden" name="product_id" value="product_7" /> <input type="hidden" name="product_id" value="product_314" />

    Then in your code, you just read off your products (example assumes that you're using CGI.pm:

    my @products = $cgi->param('product_id');

    This is very easy to implement, but it does mean that the user might not be able to visit another site and come back as these are maintained across a series of form submissions.

    A cleaner method is to give the user a cookie with an anonymous session id and use this to look up the user's session data in a database or session file. This takes more work, but it means that the user can leave and come back later and still have the products they selected. It's also probably lower bandwidth.

    Cheers,
    Ovid

    New address of my CGI Course.

Re: Selecting Items Across multiple screen.
by eric256 (Parson) on Apr 23, 2004 at 16:09 UTC

    One way would be to have all the elements present but only show those elements that are set. Then every time the user submits the form all values are included. An alternative would be to use sessions (CGI::Sessions) and store the info in there until you want to process it. A third way (i'm sure there are more but this is what i've got so far) would be to somehow incode the values and store them in a single hidden feild on each page. Perhaps using Storable to store a hash with all the values. You do want to make sure that you are using post instead of get (or vice versa i can never remember - the one that doesn't make them part of the URL). The reason being that URL's can be subjected to unwanted size limitations by certain evil browsers.


    ___________
    Eric Hodges
Re: Selecting Items Across multiple screen.
by sgifford (Prior) on Apr 23, 2004 at 16:16 UTC

    The easiest thing to do is to keep the information in hidden fields, passed from form to form.

    Because you have so much data, though, you may find it better to use sessions. Search CPAN for Session to find several modules that can help you with this. Sessions store a unique identifier on the user's client, in a hidden form field or a cookie, then store all of the information associated with that user on the server. When the user connects, it figures out where to get and store that information by the unique identifier.

Re: Selecting Items Across multiple screen.
by pizza_milkshake (Monk) on Apr 23, 2004 at 18:22 UTC
    install mod_perl. keep the data from previous screens either in a database table and/or a user session.

    perl -e'$_="nwdd\x7F^n\x7Flm{{llql0}qs\x14";s/./chr(ord$&^30)/ge;print'

      What does mod_perl have to do with base session functionality?