<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>

CC BY-SA 4.0
2016-10-15T00:07:09.547Z
2019-04-01T17:22:55.197Z
2019-04-01T17:22:55.197Z
carlcs
<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>

CC BY-SA 3.0
2016-10-15T18:02:59.200Z
Would you mind sharing your solution? Might be helpful for someone in the future!
Brad Bell
CC BY-SA 3.0
2017-09-29T19:40:29.783Z
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!
Steven Thate
CC BY-SA 3.0
2016-10-15T06:25:22.000Z
2016-10-16T08:04:29.670Z
2016-10-16T08:04:29.670Z
Filip Iversen
<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>

CC BY-SA 3.0
2016-10-14T19:43:29.470Z
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.
Brad Bell
CC BY-SA 3.0
2016-10-15T06:24:27.947Z
That is correct!
Filip Iversen
<users><relations><form><entry>
Editing entry in front-end
# 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.







{# Start with the top-level Super Table field #}


{# Ensure any existing rows in your Super Table field are saved #}
{% for block in annonse[fieldHandle] %}
                            

{% endfor %}

{# Add a new row of data - note the `new1` #}



{# Repeat for all your fields in your Super Table field #}




    Submit

> **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.


---

