Answers.Body: <p>The way you've set it up now, it won't be possible without doing 2 requests: one to create the wish, and one to alter the project (add the wish relation).</p>
  
  <p>If you'd turn it around, and give the wish section a field 'belongsToProject' (or whatever else you'd like to call it), you'd be able to create this hidden input field in your wish form:</p>
  
  <pre><code>&lt;input type="hidden" name="fields[belongsToProject][]" value="{{ project.id }}" /&gt;
  </code></pre>
  
  <p>Notice the <code>[]</code>. Those are needed because a relation field can have multiple related elements, even if you limit it to have only one.
  On saving, the field will be populated with the project relation you're looking for.</p>
  
  <p>On viewing your projects and wishes, assuming you have a variable called project with your current project in it, you could simply do:</p>
  
  <pre><code>{% set wishesForProject = craft.entries.find({
      section: 'wishes',
      relatedTo: {
          targetElement: project,
          field: 'belongsToProject',
      },
  }) %}
  
  {% for wish in wishesForProject %}
      {{ wish.title }}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-20T07:32:26.873Z
Answers.LastActivityDate: 2014-11-20T07:32:26.873Z
Answers.UserDisplayName: Paul
Body: <p>I have a channel projects and a channel wishes (People can submit their 'wishes' for that particular project. </p>
  
  <p>In a project I made the 'entry field' projectHasWishes to connect wishes to project. </p>
  
  <p>Now we use guestentries plugin to get wishes from the visitors. This form is that particular projectpage on the frontend. How can I relate them easily to the right project? Can I use a hidden field for this? Or something else? Thanks for helping me out. </p>
  
Tags: <entries><form><relations><guest-entries>
Title: Getting related project of a submitted 'wish' through the entry field.
ThreadText: # Getting related project of a submitted 'wish' through the entry field.
  
  (Asked by: username_0 on 2014-11-20)
  
  I have a channel projects and a channel wishes (People can submit their 'wishes' for that particular project.
  
  In a project I made the 'entry field' projectHasWishes to connect wishes to project.
  
  Now we use guestentries plugin to get wishes from the visitors. This form is that particular projectpage on the frontend. How can I relate them easily to the right project? Can I use a hidden field for this? Or something else? Thanks for helping me out.
  
  **Tags:** entries, form, relations, guest-entries
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-11-20. Score: 4 | Accepted answer
  
  The way you've set it up now, it won't be possible without doing 2 requests: one to create the wish, and one to alter the project (add the wish relation).
  
  If you'd turn it around, and give the wish section a field 'belongsToProject' (or whatever else you'd like to call it), you'd be able to create this hidden input field in your wish form:
  
  ```
  <input type="hidden" name="fields[belongsToProject][]" value="{{ project.id }}" />
  
  ```
  
  Notice the `[]`. Those are needed because a relation field can have multiple related elements, even if you limit it to have only one.
  On saving, the field will be populated with the project relation you're looking for.
  
  On viewing your projects and wishes, assuming you have a variable called project with your current project in it, you could simply do:
  
  ```
  {% set wishesForProject = craft.entries.find({
      section: 'wishes',
      relatedTo: {
          targetElement: project,
          field: 'belongsToProject',
      },
  }) %}
  
  {% for wish in wishesForProject %}
      {{ wish.title }}
  {% endfor %}
  
  ```
  
  
  ---
  
  