<p>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.</p>

<p>You need a hidden field like this for the child registristration.</p>

<pre><code>{% parentId = entry.authorId %}
...
&lt;input type="hidden" name="fields[parentUsersField][]" value="{{ parentId }}"&gt;
</code></pre>

<p>You can now link to the child entry and allow the parent to enter the questionair form.</p>

<pre><code>{% set childId = entry.id %}
...
&lt;input type="hidden" name="fields[childEntriesField][]" value="{{ childId }}"&gt;
</code></pre>

<p>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. <a href="https://craftcms.stackexchange.com/q/2936/125">"Creating comments via a related section"</a>).</p>

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

CC BY-SA 3.0
2015-03-06T17:13:34.253Z
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
CC BY-SA 3.0
2015-03-06T10:47:54.083Z
2015-03-06T10:53:54.333Z
2017-04-13T12:51:00.160Z
carlcs
<p>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.</p>

<p>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. </p>

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

<p>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.</p>

<p>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.</p>

<p>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.</p>

<p>Hope this is clear, and thanks for any suggestions! </p>

<relations><structure>
Setting User field type from a front end form
# Setting User field type from a front end form

(Asked by: username_0 on 2015-03-06)

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!

**Tags:** relations, structure

---

## 1 answers

### Answer by username_1 on 2015-03-06. Score: 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 %}
...


You can now link to the child entry and allow the parent to enter the questionair form.
{% set childId = entry.id %}
...


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.

> **Comments:**
> **username_0**: 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!  

---

