Page 1 of 1

Retaining checkbox values through pages HELP

Posted: Mon Oct 07, 2002 9:24 pm
by lm3288
Hi everyone,
I have a script that displays a list of names from a database that can be
added into a mailing list by checking the checkbox next to the name.

The names are listed at 10 names per page, with links to the next or
previous 10 names.
let's say i check some names on page one, then i move on to page two and
check some names there. is there a way to remember these names as i browse
thru the pages? that is to say, is there a way to remember who i checked on page one if i come back to it again?

Thanks in advance for any help
:roll:

Posted: Mon Oct 07, 2002 9:54 pm
by volka
you can keep those values either stored as hidden-field within the form or as session-array.
The tricky part will be to determine the checkboxes that are already marked as selected and the array-elements that should be unset if a user goes back a/some page/s and changes the selections :?
I would keep all selected values in a session array and send with every form a hidden field that contains a serialized array with all possible entries for this page (*). When the user presses one of the submit-buttons (prevoius/next-page button would be submits with another value-property) the script would append all selected values to the session-array and unset all remaining (in the serialized array but not selected in the form) entries.

(*) this depends on how complex it is to retrieve this information. If it is as easy as 'page 2 --> SELECT .... LIMIT 20,10' I would rather re-query this information than depend on the data that is transmitted back from the client (where all those nasty users can play tricks on the data ;) )

check box arrays

Posted: Thu Oct 10, 2002 3:32 pm
by phpScott
If the check boxes are all the same name then they are already listed in a php array of the same name. When I have to create check boxes out of a db a let php do the work and create the check boxes. If I am comparing to tables together I create a hidden field with a different name from the checkboxes but the same name for all the hidden fields this will create another php array.
IE newCheckboxes for the phone number list,
and hidden fields for the already existing selections.
when creating the checkboxes I then compare the lists and if they match set the check box to selected.

If you echo out the array in a hidden field then of course it will be passed along to the next page.

phpScott