Answers.Body: <p>You guessed right, you have to set all already added entries again. To do this,
  just have some Twig logic when outputting the fields:</p>
  
  <pre><code>{% for currentTeam in entry.tournamentTeams %}
      &lt;input type="hidden" name="fields[tournamentTeams][]" value="{{ currentTeam.id }}"&gt;
  {% endfor %}
  &lt;input type="hidden" name="fields[tournamentTeams][]" value="{{ team.id }}"&gt;
  </code></pre>
  
  <p>To remove the entry:</p>
  
  <pre><code>{% for currentTeam in entry.tournamentTeams if currentTeam.id != team.id %}
      &lt;input type="hidden" name="fields[tournamentTeams][]" value="{{ currentTeam.id }}"&gt;
  {% endfor %}
  </code></pre>
  
  <p><strong>Update:</strong> What I'm not sure about is if the above code works when trying to remove the last remaining entry. If it doesn't work I'd try and add something like this:</p>
  
  <pre><code>{% if (entry.tournamentTeams|length == 1) and (entry.tournamentTeams.first().id == team.id) %}
      &lt;input type="hidden" name="fields[tournamentTeams]" value=""&gt;
  {% endif %}
  </code></pre>
  
  <hr>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-21T01:40:14.957Z
Answers.Text: so I didn't do my thorough testing with this... I did run into an issue with the last remaining entry. Unfortunately, your snippet does not work... Any other ideas?
Answers.UserDisplayName: Chase Giunta
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-21T01:47:05.887Z
Answers.Text: ah! turns out it was the brackets suffix in the `name` attribute. It wasn't necessary. I updated the answer :)
Answers.UserDisplayName: Chase Giunta
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-30T22:02:47.570Z
Answers.LastActivityDate: 2015-09-21T17:00:49.380Z
Answers.LastEditDate: 2015-09-21T17:00:49.380Z
Answers.UserDisplayName: carlcs
Body: <p>I'm making a one-button form, to add an entry to an entries field.
  Adding seems pretty straightforward, but it overwrites any previous entry that occupied the entries field. How would I append an entry to the entries field, or remove an entry?</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8"&gt;
    {{ getCsrfInput() }}
    &lt;input type="hidden" name="action" value="entries/saveEntry"&gt;
    &lt;input type="hidden" name="entryId" value="{{ entry.id }}"&gt;
    &lt;input type="hidden" name="redirect" value="{{currentUrl}}"&gt;
    &lt;input type="hidden" name="fields[tournamentTeams][]" value="{{team.id}}"&gt;
  
    &lt;input type="submit" value="Add {{team.title}} to this Tournament"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My guess is, I will have to populate the entries field input value with the already-added entries to append the entry, and do the same kinda deal upon removing the entry- no idea how I would detect and remove the entry though!</p>
  
Tags: <form><entries-field><frontend>
Title: Add, remove, and append entries to an entries field via frontend form
ThreadText: # Add, remove, and append entries to an entries field via frontend form
  
  (Asked by: username_0 on 2015-08-30)
  
  I'm making a one-button form, to add an entry to an entries field.
  Adding seems pretty straightforward, but it overwrites any previous entry that occupied the entries field. How would I append an entry to the entries field, or remove an entry?
  
  ```
  <form method="post" accept-charset="UTF-8">
    {{ getCsrfInput() }}
    <input type="hidden" name="action" value="entries/saveEntry">
    <input type="hidden" name="entryId" value="{{ entry.id }}">
    <input type="hidden" name="redirect" value="{{currentUrl}}">
    <input type="hidden" name="fields[tournamentTeams][]" value="{{team.id}}">
  
    <input type="submit" value="Add {{team.title}} to this Tournament">
  </form>
  
  ```
  
  My guess is, I will have to populate the entries field input value with the already-added entries to append the entry, and do the same kinda deal upon removing the entry- no idea how I would detect and remove the entry though!
  
  **Tags:** form, entries-field, frontend
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-30. Score: 3 | Accepted answer
  
  You guessed right, you have to set all already added entries again. To do this,
  just have some Twig logic when outputting the fields:
  
  ```
  {% for currentTeam in entry.tournamentTeams %}
      <input type="hidden" name="fields[tournamentTeams][]" value="{{ currentTeam.id }}">
  {% endfor %}
  <input type="hidden" name="fields[tournamentTeams][]" value="{{ team.id }}">
  
  ```
  
  To remove the entry:
  
  ```
  {% for currentTeam in entry.tournamentTeams if currentTeam.id != team.id %}
      <input type="hidden" name="fields[tournamentTeams][]" value="{{ currentTeam.id }}">
  {% endfor %}
  
  ```
  
  **Update:** What I'm not sure about is if the above code works when trying to remove the last remaining entry. If it doesn't work I'd try and add something like this:
  
  ```
  {% if (entry.tournamentTeams|length == 1) and (entry.tournamentTeams.first().id == team.id) %}
      <input type="hidden" name="fields[tournamentTeams]" value="">
  {% endif %}
  
  ```
  
  ---
  
  > **Comments:**
  > **username_0**: so I didn't do my thorough testing with this... I did run into an issue with the last remaining entry. Unfortunately, your snippet does not work... Any other ideas?  
  > **username_0**: ah! turns out it was the brackets suffix in the `name` attribute. It wasn't necessary. I updated the answer :)  
  
  ---
  
  