Answers.Body: <p>Looks like you want to implement a feature to vote for entries. Have a look at these plugins, they make this really easy for you.</p>
  
  <ul>
  <li><a href="https://www.doublesecretagency.com/plugins/upvote" rel="nofollow noreferrer">https://www.doublesecretagency.com/plugins/upvote</a></li>
  <li><a href="https://github.com/dukt/craft-like" rel="nofollow noreferrer">https://github.com/dukt/craft-like</a></li>
  </ul>
  
  <p>If you want to implement something yourself, I would look into adding the button behavior using JavaScript, listen for click events and send the data over XMLHttpRequests to the entries/saveEntry controller.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2016-10-15T00:07:09.547Z
Answers.LastActivityDate: 2019-04-01T17:22:55.197Z
Answers.LastEditDate: 2019-04-01T17:22:55.197Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>I managed to find a solution, using hidden input fields :) Thank you for all the help :)</p>
  
  <p>Edit: Ended up solving this by using tables and saving the username and ID in that. Used a plugin called Super Tables, which gives you a lot more control over the table.</p>
  
  <pre><code>&lt;input type="hidden" name="action" value="entries/saveEntry"&gt;
  &lt;input type="hidden" name="userId" value="{{ currentUser.id }}"&gt;
  &lt;input type="hidden" name="redirect" value="/#{{ annonse.title }}{{ annonse.annonsePremie }}"&gt;
  &lt;input type="hidden" name="sectionId" value="{{ annonse.sectionId }}"&gt;
  &lt;input type="hidden" name="entryId" value="{{ annonse.id }}"&gt;
  &lt;input type="hidden" name="enabled" value="1"&gt;
  
  {# Start with the top-level Super Table field #}
  &lt;input type="hidden" name="fields[{{ fieldHandle }}]" value=""&gt;
  
  {# Ensure any existing rows in your Super Table field are saved #}
  {% for block in annonse[fieldHandle] %}
                              &lt;input type="hidden" name="fields[{{ fieldHandle }}][{{ block.id }}][type]" value="{{ blocktype }}"&gt;
  &lt;input type="hidden" name="fields[{{ fieldHandle }}][{{ block.id }}][enabled]" value="1"&gt;
  {% endfor %}
  
  {# Add a new row of data - note the `new1` #}
  &lt;input type="hidden" name="fields[{{ fieldHandle }}][new1][type]" value="{{ blocktype }}"&gt;
  &lt;input type="hidden" name="fields[{{ fieldHandle }}][new1][enabled]" value="1"&gt;
  
  {# Repeat for all your fields in your Super Table field #}
  &lt;input type="hidden" name="fields[{{ fieldHandle }}][new1][fields][bruker]" value="{{ currentUser }}"&gt;
  &lt;input type="hidden" name="fields[{{ fieldHandle }}][new1][fields][brukerId]" value="{{ currentUser.id }}"&gt;
  
  &lt;button class="button submit" type="submit"&gt;
      &lt;p&gt;Submit&lt;/p&gt;
  &lt;/button&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-15T18:02:59.200Z
Answers.Text: Would you mind sharing your solution? Might be helpful for someone in the future!
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-29T19:40:29.783Z
Answers.Text: I have been trying for days to correctly save to my matrix field from a front end form. The code you provided in your own answer finally gave me the missing piece!! Thank you!
Answers.UserDisplayName: Steven Thate
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-15T06:25:22.000Z
Answers.LastActivityDate: 2016-10-16T08:04:29.670Z
Answers.LastEditDate: 2016-10-16T08:04:29.670Z
Answers.UserDisplayName: Filip Iversen
Body: <p>I am trying to edit an entry automatically when you press a button. Is there a way to do this? </p>
  
  <p>A bit more detail: I have listed up a few entries, each with their own button. When I press the button on a specific entry, I want the currentUser to be added to the User Field of that entry.</p>
  
  <p>Currently I have managed to get this semi-working with a form where the user can edit the entry through input fields etc., changing their value, then submiting (as outlined under <a href="https://craftcms.com/docs/templating/entry-form" rel="nofollow">Entry Form</a> in the docs). This is the prossess I want automated. When you press the button in the front-end the entry is edited with values set in the code and submitted. </p>
  
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-14T19:43:29.470Z
Comments.Text: Just trying to wrap my head around what you're going for. You've displaying a list of entries on the front-end. Each entry has a button. When a logged in user clicks one of the buttons, you want that user added to a Users field on that entry.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-15T06:24:27.947Z
Comments.Text: That is correct!
Comments.UserDisplayName: Filip Iversen
Tags: <users><relations><form><entry>
Title: Editing entry in front-end
ThreadText: # Editing entry in front-end
  
  (Asked by: username_0 on 2016-10-14)
  
  I am trying to edit an entry automatically when you press a button. Is there a way to do this?
  
  A bit more detail: I have listed up a few entries, each with their own button. When I press the button on a specific entry, I want the currentUser to be added to the User Field of that entry.
  
  Currently I have managed to get this semi-working with a form where the user can edit the entry through input fields etc., changing their value, then submiting (as outlined under [Entry Form](https://craftcms.com/docs/templating/entry-form) in the docs). This is the prossess I want automated. When you press the button in the front-end the entry is edited with values set in the code and submitted.
  
  Thanks!
  
  **Tags:** users, relations, form, entry
  
  > **Comments:**
  > **username_1**: Just trying to wrap my head around what you're going for. You've displaying a list of entries on the front-end. Each entry has a button. When a logged in user clicks one of the buttons, you want that user added to a Users field on that entry.  
  > **username_0**: That is correct!  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2016-10-15. Score: 4 | Accepted answer
  
  I managed to find a solution, using hidden input fields :) Thank you for all the help :)
  
  Edit: Ended up solving this by using tables and saving the username and ID in that. Used a plugin called Super Tables, which gives you a lot more control over the table.
  
  ```
  <input type="hidden" name="action" value="entries/saveEntry">
  <input type="hidden" name="userId" value="{{ currentUser.id }}">
  <input type="hidden" name="redirect" value="/#{{ annonse.title }}{{ annonse.annonsePremie }}">
  <input type="hidden" name="sectionId" value="{{ annonse.sectionId }}">
  <input type="hidden" name="entryId" value="{{ annonse.id }}">
  <input type="hidden" name="enabled" value="1">
  
  {# Start with the top-level Super Table field #}
  <input type="hidden" name="fields[{{ fieldHandle }}]" value="">
  
  {# Ensure any existing rows in your Super Table field are saved #}
  {% for block in annonse[fieldHandle] %}
                              <input type="hidden" name="fields[{{ fieldHandle }}][{{ block.id }}][type]" value="{{ blocktype }}">
  <input type="hidden" name="fields[{{ fieldHandle }}][{{ block.id }}][enabled]" value="1">
  {% endfor %}
  
  {# Add a new row of data - note the `new1` #}
  <input type="hidden" name="fields[{{ fieldHandle }}][new1][type]" value="{{ blocktype }}">
  <input type="hidden" name="fields[{{ fieldHandle }}][new1][enabled]" value="1">
  
  {# Repeat for all your fields in your Super Table field #}
  <input type="hidden" name="fields[{{ fieldHandle }}][new1][fields][bruker]" value="{{ currentUser }}">
  <input type="hidden" name="fields[{{ fieldHandle }}][new1][fields][brukerId]" value="{{ currentUser.id }}">
  
  <button class="button submit" type="submit">
      <p>Submit</p>
  </button>
  
  ```
  
  > **Comments:**
  > **username_1**: Would you mind sharing your solution? Might be helpful for someone in the future!  
  > **username_3**: I have been trying for days to correctly save to my matrix field from a front end form. The code you provided in your own answer finally gave me the missing piece!! Thank you!  
  
  ---
  
  ### Answer by username_2 on 2016-10-15. Score: 3
  
  Looks like you want to implement a feature to vote for entries. Have a look at these plugins, they make this really easy for you.
  
  * <https://www.doublesecretagency.com/plugins/upvote>
  * <https://github.com/dukt/craft-like>
  
  If you want to implement something yourself, I would look into adding the button behavior using JavaScript, listen for click events and send the data over XMLHttpRequests to the entries/saveEntry controller.
  
  
  ---
  
  