I am making a web app where users can create polls. I have a poll <form>
that the user creates, with a dynamic number of poll questions (they add questions to the poll creation front-end with a little bit of javascript). Because the form fields are not predefined, the <input>
tags don't have unique names. (Is this wrong? If so, how should I resolve the problem?)
Here's an example structure:
<!-- question type with only one data input, eg "Do you like carrots?" -->
<input type="select" value="carrots" />
<!--confidence interval relating to single input question -->
<input type="select" value="10%" />
<!-- question type with multiple data inputs, eg "Which do you prefer?" -->
<input type="select" value="carrots" />
<input type="select" value="cake" />
<input type="select" value="corn" />
<!--confidence interval relating to multiple input question -->
<input type="select" value="5%" />
<!-- (more poll questions follow...) -->
How should I "group" all these inputs together in the POST data so that I know which confidence level input corresponds to which question type input (eg 10% goes with "Do you like carrots", and also which elements should be grouped for questions with multiple elements (carrots, cake, corn...). Normally these relations are coded into the relational database, but due to the dynamic stuff going on, that implicit relationship (1 form = 1 object) can't be relied upon. (The back-end is Django, if it matters).
Edit: I'm aware of form prefixing, but questions with multiple data inputs are also normalized (each carrot, cake, corn etc is an object in its own right, referenced by a ManyToManyField
), and so I believe form-prefixing can't handle two levels of normalization (many questions per poll + many foods per question).