views:

106

answers:

2

Assuming of course we're working with HTML Forms and GET/POST data, backend language agnostic. Asker is most fluent with PHP and Python.

Example: Tracking event attendance, there is an HTML page for the event administration that lists all available People. There is a column next to each name with a graphic/widget representing their attendance for the event. What's the best way to update the Attendance status for a Person on the list?

One method I initially thought of was simply to use a Checkbox for attendance. However, unchecked boxes aren't sent along with form data. The underlying logic would have to toggle the Attendance status to FALSE/OFF/Not Attending for any Person ID not sent along with the form. This breaks if the list is paginated!

The second method I thought about was using a graphic/button next to each name. Is it appropriate that each button be a submit button? As in: Is is allowed that a form element have multiple submit buttons? Or should each button/Person be wrapped in it's own form element?

+1  A: 

A fairly simple fix is to go with your checkbox method, but add a couple of hidden form elements that store values for the minimum/maximum values that are going to be submitted. That way your logic can handle "missing" checkboxes as "off" without breaking everyone that isn't on the page.

I don't recommend having multiple submit elements in a single form. If you want to go another direction, you could look into having a link (textual/graphic/button) on each row that uses ajax to toggle the attendance for that row's person. That way nothing ever has to be explicitly "submitted" by the user. As they toggle on the interface, updates happen in the background.

Chad Birch
A good answer, and I'd like to expand what's here: That works based on a numeric key, and where the Person records are contiguous. Otherwise (filtered/sorted by first name) this method would have to include a list of all People IDs on the page. It seems a bit clunky, but could work.
anonymous coward
Well, the min/max values could be whatever the page was using to sort. Passing names as the min/max would work just as well, as long as the form-processing page uses those to fetch the list of valid IDs from the data. It doesn't necessarily need to be contiguous, the min/max should just be used to set bounds on selecting a list of valid IDs, which can then be checked against the list of checkbox values.
Chad Birch
An additional note about my above comment, it would require a third hidden value representing what the sorting method was, so for example you could pass the 3 values: sort="lastName", min="Adams", max="Carson" and have the form-processing page select all the person IDs from the database where the last name is between Adams and Carson.
Chad Birch
I'm selecting this answer for the AJAX method selection. Since doing the research, I realized that I was asking for the wrong thing, as with "best practices" there just isn't a good way to do this without relying on something like AJAX being present. Using the standard checkboxes and a single submit with options to "Mark Selected As..." is best. For "Single Click", AJAX would come into play.
anonymous coward
A: 

Just like with any other "Edit Record" or "Delete This Row" button, the toggle buttons could be a Submit button/graphic element with the unique record ID (or whatever the case) to Update/Toggle/Delete in the value attribute.

The form handler would only need to check the value of the submit button (which may need a unique name attribute).

Please correct me if I'm wrong, but I believe that this is okay and valid in at least HTML4 and XHTML1.

anonymous coward
I believe it's valid, and should work, but it will probably be somewhat annoying to the user, having a full reload every time they toggle one row.
Chad Birch