in reply to Organizing Form Input

Like blue_cowdawg, I'm a little confused about your premise, and I would like to understand it better.

users are encouraged to fill in a form with a varying number of fields
I understand "a field on an html form" as being a particular, distinct input element (type-in, radiobutton, etc), so I can't figure out how a form can have a varying number of fields when javascript is disabled. If you meant something else, could you please explain?

- all of the fields have the same basic premise(being an answer to a question),
Combining this with the "variable number" issue, what does this imply?
  1. A given question can have one or more answers, or
  2. There can be a variable number of questions, at the user's discretion, each having one answer, or
  3. The user can add questions and have multiple answers on any given question.
Personally, I would expect a good solution to be different depending on which of those three describes the problem. (But there might be a suitable abstraction that I'm not seeing.)

Users are able to dynamically add fields(which would also mean dynamically naming them)
This sort of reiterates the two preceding questions. Does it imply dynamically adding the form input methods, whether or not javascript is enabled? And, does it imply that the user is adding questions, or extra answers to a given question, or both?

Assuming, as andyford does, that non-javascript users need a round-trip transaction with the server each time they add a new input element to the form, managing the naming seems like a trivial issue. To allow the javascript-enabled users to "economize" on all that back-and-forth traffic, the first problem (seemingly trivial) would simply be to make sure that the javascript uses the same strategy as the server-side cgi script when assigning names to newly added fields, so that the end result is the same no matter what sort of user is involved.

In either case, it seems like the more challenging issues revolve around how to make all this coherent to the users, so they understand what is expected of them. After that, there might be a strategy question about how to organize the code to reduce the maintenance pains that are bound to arise from having two implementations (with and without javascript) for "the same thing".

Hmm. That makes me wonder... how hard would it be to write a perl module for creating (some portion of) a web form, such that a perl function could be written to translate that module's code into equivalent, working javascript? (Or maybe there's some way of specifying a form layout, such that it can be used to automatically generate both perl code and javascript code to implement it?)

Replies are listed 'Best First'.
Re^2: Organizing Form Input
by Spidy (Chaplain) on Feb 24, 2007 at 17:43 UTC

    Basically, the users are adding questions to a quiz. They are able to type in the text of the question, one right answer, and as many wrong answers as they want to. Instead of just offering up 62 input boxes for wrong answers and saying "fill out as many as you can", I would rather offer just one and an option to "add another answer".

      That doesn't seem so hard, and I could imagine a couple different ways to do this with minimum back-and-forth for non-javascript users -- and no real need for javascript at all, really.

      One way: a specific form/submit button is used to add a question, and there's a type-in to accept the number of possible answers to make available (either including the right answer, or in addition to it), and this defaults to some reasonable value. On submitting this, a second form is given with type-ins for the question itself, and for the requested number of answers.

      Another way: when responding to a request to add a question (no other parameter needed), simply provide three text entry boxes: one for the question, one for the right answer, and a larger (scrollable) one for a list of wrong answers, with instructions on how to mark the boundaries between distinct wrong answers in this box (e.g. use "===" or something like that). So long as you provide a "preview" stage (like PM does), this should work fine.

      In either case, all the components for a new question are submitted at one time; you just need to name and maintain the user/quiz-id and the question-id within the quiz, and based on those, it's simple enough to identify make up identifiers for the "correct answer" string and each of the "wrong answer" strings.