I'm working on a Craft CMS plugin. I'm making a form that consists of multiple themes and questions. The structure is supposed to be as follows:
• Form
• Theme
• Question
• Question
• Question
• Theme
• Question
• Question
Questions should be “attached” to the form with the formId, but also to their respective themeId. This kinda works when there’s just one theme, but as soon as I save a question in a second or third theme, all questions get the last theme id.
I’ve added a hidden field to each question which looks like this:
<input type="hidden" class="questionThemeId" name="questionThemeId" value="{{ themeId }}">
Then in my Service I do the following request and add the themeId to the question.
$themeIdForQuestion = craft()->request->getPost("questionThemeId");
$question->themeId = $themeIdForQuestion;
This does add the themeId to the question, but once there is a question in the second theme, all questions get the themeId of the last theme. That makes sense, because getPost always gets the last post (I think). How would I get post of the questionThemeId depending on the question?
I'm open to other solutions too, because this does feel slightly hacky.
Thanks!