<p>Without looking at the core code, I imagine that the <code>setpassword</code> action is only looking for the very specific fields it needs to reset the users password, saving the record, and redirecting to the next screen.</p>
<p>You could try creating a custom module that includes a hook to listen for the <code>craft\elements\User::EVENT_BEFORE_SAVE</code> event trigger.</p>
<p>Within that hook you could check the payload of the POST submission to see if it contains data from the extra fields you included, and if it does, manually set them in the user record that's about to be saved.</p>
<p>Maybe something roughly like this:</p>
<pre><code>use yii\base\Event;
use craft\elements\User;
use craft\events\ModelEvent;

Event::on(
    User::class,
    User::EVENT_BEFORE_SAVE,
    function (ModelEvent $event) {
        $user = $event-&gt;element;

        if( !empty( craft.app.request.getBodyParam('YOUR_CUSTOM_FIELD') ) ) {
            $user-&gt;setFieldValue(
                'FIELD_NAME',
                craft.app.request.getBodyParam('YOUR_CUSTOM_FIELD')
            );
        }

        // repeat for other fields you're saving
        // ... etc
    }
);
</code></pre>

CC BY-SA 4.0
2021-12-20T19:37:11.820Z
2021-12-20T19:37:11.820Z
stevecomrie
<p>I created a custom setpassword template which I largely copied from the default one except that I added <code>firstName</code>, <code>lastName</code> and <code>photo</code> fields so that the user can set up their whole account at the same time (the reason for their name not being entered earlier is that the users are created/invited by other users who may not have their name). But it seems that my added fields are being ignored in the submission. I assume it has something to do with the <code>code</code> that is being submitted in the form (and is in the query string) being very specific to one purpose here.</p>
<p>So any tips on the best way to do what I'm after, or am I just going to have to make it a 2 screen operation?</p>

<registration><password><activation>
Custom setpassword screen with added fields
# Custom setpassword screen with added fields

(Asked by: username_0 on 2021-12-20)

I created a custom setpassword template which I largely copied from the default one except that I added `firstName`, `lastName` and `photo` fields so that the user can set up their whole account at the same time (the reason for their name not being entered earlier is that the users are created/invited by other users who may not have their name). But it seems that my added fields are being ignored in the submission. I assume it has something to do with the `code` that is being submitted in the form (and is in the query string) being very specific to one purpose here.

So any tips on the best way to do what I'm after, or am I just going to have to make it a 2 screen operation?

**Tags:** registration, password, activation


---

## 1 answers

### Answer by username_1 on 2021-12-20. Score: 1

Without looking at the core code, I imagine that the setpassword action is only looking for the very specific fields it needs to reset the users password, saving the record, and redirecting to the next screen.
You could try creating a custom module that includes a hook to listen for the craft\elements\User::EVENT_BEFORE_SAVE event trigger.
Within that hook you could check the payload of the POST submission to see if it contains data from the extra fields you included, and if it does, manually set them in the user record that's about to be saved.
Maybe something roughly like this:
use yii\base\Event;
use craft\elements\User;
use craft\events\ModelEvent;

Event::on(
    User::class,
    User::EVENT_BEFORE_SAVE,
    function (ModelEvent $event) {
        $user = $event->element;

        if( !empty( craft.app.request.getBodyParam('YOUR_CUSTOM_FIELD') ) ) {
            $user->setFieldValue(
                'FIELD_NAME',
                craft.app.request.getBodyParam('YOUR_CUSTOM_FIELD')
            );
        }

        // repeat for other fields you're saving
        // ... etc
    }
);


---

