<p>I'd add an Entries field in your User field layout called <code>Articles Read</code> or such. Then whenever they click that they've read a particular article, I'd add the <code>id</code> of article entry that they've read to that field.</p>

<p>I'd do that probably via a custom plugin, but you could also do it with a simple form that passes the correct data to the the <code>actionUrl('users/save-user')</code> UsersController</p>

CC BY-SA 4.0
2018-07-24T04:29:23.293Z
how could i go about doing this inside the template file exactly? I've tried to use the save-user action url but when it submits it says they have read every article on the page rather than just the article they clicked they read (if this makes sense). I appreciate your help so far, thank you
Kevin Love
CC BY-SA 4.0
2018-07-23T23:56:12.660Z
2018-07-23T23:56:12.660Z
andrew.welch
<p>In addition to Andrews answer just a little example how to store information for a user via custom plugin. There are many resources how to create a plugin, <a href="https://nystudio107.com/blog/so-you-wanna-make-a-craft-3-plugin" rel="nofollow noreferrer">so [if] you wanna make a Craft 3 plugin</a> you should read those.</p>

<p>You form could look like this</p>

<pre class="lang-html prettyprint-override"><code>&lt;form method="post" accept-charset="UTF-8"&gt;
    {{ csrfInput() }}
    &lt;input type="hidden" name="action" value="plugin/controller/function"&gt;
    &lt;input type="hidden" name="entryId" value="1"&gt;
    &lt;button type="submit"&gt;Submit&lt;/button&gt;
&lt;/form&gt;
</code></pre>

<p>And your controller</p>

<pre class="lang-php prettyprint-override"><code>public function actionSave():Response
{
    $user = Craft::$app-&gt;getUser()-&gt;getIdentity();
    if($user === null){
        // error, no user is logged in
        // handle it somehow
    }

    // check for a valid entry id
    $newId = Craft::$app-&gt;getRequest()-&gt;getBodyParam('entryId');
    if($newId === null){
        // error, no entry id provided...
    }

    // get the existing entries and add the new one to the array
    $existingIds = $user-&gt;getFieldValue('fieldHandle')-&gt;ids();
    $existingIds[] = $newId;

    // set the new value and store the element
    $user-&gt;setFieldValue('fieldHandle', $existingIds);
    if(!Craft::$app-&gt;getElements()-&gt;saveElement($user)){
        // could not save user due to validation errors, do something about it
    }

    // everything was successful, render a template or redirect or whatever you need
    return $this-&gt;renderTemplate('some/path', ['message' =&gt; 'hooooray']);
}
</code></pre>

CC BY-SA 4.0
2018-07-24T21:50:18.443Z
i created a plugin, but for some reason cannot hit that path to my controller with the function, it just tells me the page doesnt exist. any ideas?
Kevin Love
CC BY-SA 4.0
2018-07-24T22:08:07.647Z
Without seeing your code? No - but that's a different question, please visit slack to get in touch or ask a new question to keep everything clean
Robin Schambach
CC BY-SA 4.0
2018-07-24T22:09:44.447Z
I actually got the correct value now and the form is submitting, however i created the field for the entry, but not sure what to do next. i was a bit unclear on addin the field to the user field or the entry field.
Kevin Love
CC BY-SA 4.0
2018-07-24T22:11:39.487Z
You should add the `entries` field to the user as @andrew.welch suggested. You can store every entry in your users.
Robin Schambach
CC BY-SA 4.0
2018-07-25T04:05:14.587Z
I got exactly what i needed, however there's one more thing, on the return after the function runs, the redirect, i want to disable a button after submission that states they finished the course.
Kevin Love
CC BY-SA 4.0
2018-07-24T17:41:11.027Z
2018-07-24T17:41:11.027Z
Robin Schambach
<p>I'm working on a project using Craft CMS for the first time, so far so good, however i'm stumped on how to do the following:</p>

<p>Create a button on each entry in a structure that states you have read the follow article. When you click you have read the article, it reflects on your account page that you have read the follow article(s).</p>

<p>Hopefully this makes sense, but it's almost like a LMS, you learn about something on the page you click you have completed the stage then move on to the next stage.</p>

<p>Thanks!</p>

<craft3>
Entry Tracker to see who has completed the course
# Entry Tracker to see who has completed the course

(Asked by: username_0 on 2018-07-23)

I'm working on a project using Craft CMS for the first time, so far so good, however i'm stumped on how to do the following:

Create a button on each entry in a structure that states you have read the follow article. When you click you have read the article, it reflects on your account page that you have read the follow article(s).

Hopefully this makes sense, but it's almost like a LMS, you learn about something on the page you click you have completed the stage then move on to the next stage.

Thanks!

**Tags:** craft3

---

## 2 answers

### Answer by username_1 on 2018-07-23. Score: 2

I'd add an Entries field in your User field layout called `Articles Read` or such. Then whenever they click that they've read a particular article, I'd add the `id` of article entry that they've read to that field.

I'd do that probably via a custom plugin, but you could also do it with a simple form that passes the correct data to the the `actionUrl('users/save-user')` UsersController

> **Comments:**
> **username_0**: how could i go about doing this inside the template file exactly? I've tried to use the save-user action url but when it submits it says they have read every article on the page rather than just the article they clicked they read (if this makes sense). I appreciate your help so far, thank you  

---

### Answer by username_2 on 2018-07-24. Score: 1

In addition to Andrews answer just a little example how to store information for a user via custom plugin. There are many resources how to create a plugin, so [if] you wanna make a Craft 3 plugin you should read those.
You form could look like this

    {{ csrfInput() }}
    
    
    Submit


And your controller
public function actionSave():Response
{
    $user = Craft::$app->getUser()->getIdentity();
    if($user === null){
        // error, no user is logged in
        // handle it somehow
    }

    // check for a valid entry id
    $newId = Craft::$app->getRequest()->getBodyParam('entryId');
    if($newId === null){
        // error, no entry id provided...
    }

    // get the existing entries and add the new one to the array
    $existingIds = $user->getFieldValue('fieldHandle')->ids();
    $existingIds[] = $newId;

    // set the new value and store the element
    $user->setFieldValue('fieldHandle', $existingIds);
    if(!Craft::$app->getElements()->saveElement($user)){
        // could not save user due to validation errors, do something about it
    }

    // everything was successful, render a template or redirect or whatever you need
    return $this->renderTemplate('some/path', ['message' => 'hooooray']);
}

> **Comments:**
> **username_0**: i created a plugin, but for some reason cannot hit that path to my controller with the function, it just tells me the page doesnt exist. any ideas?  
> **username_2**: Without seeing your code? No - but that's a different question, please visit slack to get in touch or ask a new question to keep everything clean  
> **username_0**: I actually got the correct value now and the form is submitting, however i created the field for the entry, but not sure what to do next. i was a bit unclear on addin the field to the user field or the entry field.  
> **username_2**: You should add the `entries` field to the user as @andrew.welch suggested. You can store every entry in your users.  
> **username_0**: I got exactly what i needed, however there's one more thing, on the return after the function runs, the redirect, i want to disable a button after submission that states they finished the course.  

---

