2

I am moving a site from EE to Craft and trying to figure out the best Craft approach to something I did with lots of php and url parameters in EE.

The overview: the site is a Family Counseling Clinic. As part of their program, they have parents register as users on their site. The parents create a profile for each of their children and then, for each child, they fill out a number of questionnaires.

The basic issue is how to set up these relationships, given that I am using front end forms.

Since the parent is a registered user and is creating the child profile(s) (as a channel entry), the relationship can be based on entry.authorId(theParent). No problem there.

The relationship between child and forms is where I am looking for a Crafty solution. One obvious approach is to use Structure for the child profiles and have the questionnaires as a "child entries". The other possibility that occurs to me is to use an Entries field in a Questionnaire channel that is tied to Child channel entries.

In both cases the question is whether it is possible to do either one of those using a front end form, which would either require setting the parent entry for the Structure solution or the Entry field for the other.

Hope this is clear, and thanks for any suggestions!

4

Maybe I don't quite get your problem, but I actually don't see any difference between posting child entries (the patients) related to a parent user and posting questionair entries related to a child entry.

You need a hidden field like this for the child registristration.

{% parentId = entry.authorId %}
...
<input type="hidden" name="fields[parentUsersField][]" value="{{ parentId }}">

You can now link to the child entry and allow the parent to enter the questionair form.

{% set childId = entry.id %}
...
<input type="hidden" name="fields[childEntriesField][]" value="{{ childId }}">

Keep in mind that relation fields can hold multiple elements, even if set a limit in the field settings; so you need to post an array using the syntax show above. There's other more complete code examples here on Stack Exchange for having relational fields in a from (i.e. "Creating comments via a related section").

And yes, using a channel for the questionairs is a very flexible and clean way to structure the relation in my opinion.

  • Thanks, that is pretty much what I did in EE. What I was uncertain about was how to set a relations field, so you answered my question! – Roi Agneta Mar 6 '15 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.