How can I get custom user registration field parameters I am allowing users to register on my site. I want to have the field "full name" on the registration page which, from there I will eventually split that value to populate the first name &amp; last name fields for each user within the CP.

I have the actual in put in place:

twig

&lt;h3&gt;&lt;label for="fullName"&gt;Full Name&lt;/label&gt;&lt;/h3&gt;
&lt;input id="fullName" type="text" id="fullName" name="fields[fullName]"
{%- if account is defined %} value="{{ account.fullName }}"{% endif -%}&gt;

{% if account is defined %}
    {{ errorList(account.getErrors('fullName')) }}
{% endif %}


I have created a plugin to grab the value of the fullName input. I am using the init() method to listen for the saveUser event which is working perfectly.

MyPlugin.php

public function init()
{
    craft()-&gt;on('users.saveUser', function (Event $event) {
        error_log('-- saveUser event called --');
        error_log(print_r($event, true));

        if ($event-&gt;params['isNewUser']) {
            error_log('-- creating a new user --');

            error_log($event-&gt;params['fullName']);


            // split the fullname into firstname &amp; lastname

            // populate first name

            // populate last name

            // save the new user
        } else {
            error_log('-- updating an existing user --');
        }
    });
}


I can see the data come through in the logs, but I'm not sure how to get to it.

error_log

...
[_attributes:Craft\BaseModel:private] =&gt; Array
                            (
                                [locale] =&gt; en_us
                                [elementId] =&gt; 123
                                [fullName] =&gt; aaa bbb
                                [id] =&gt; 123
                            )
...


The "fullName" parameter is getting populated, but when I log the out put:

MyPlugin.php

error_log($event-&gt;params['fullName']);


I am getting the error Undefined index: fullName. The user is getting created.

I can get to the data using this: 

craft()-&gt;request-&gt;getPost('fields.fullName');


But then I'm not sure how to get that back into the user model so it gets saved.

EDIT

Sigh, well if it isn't obvious I don't give up too easily. I am able to capture the data like this. Is this the correct way? I will have a large number of registrations, so I'm trying to do things the correct way as much as possible.

MyPlugin.php

$event-&gt;params['fullName'] = craft()-&gt;request-&gt;getPost('fields.fullName');
error_log($event-&gt;params['fullName']);  // aaa bbb


Here is is in the CP:


The trick I'm seeing now is how to inject (for lack of better words) the values from fullName into firstName and lastName.

Here is what I am using to try to do that (without much success)

$name = explode(' ', craft()-&gt;request-&gt;getPost('fields.fullName'));
$lastName = array_pop($name);
$firstName = implode(' ', $name);

$event-&gt;params['fullName'] = craft()-&gt;request-&gt;getPost('fields.fullName');
$event-&gt;params['firstName'] = $firstName;
$event-&gt;params['lastName'] = $lastName;


"Full Name" (as you can see in the attachment) is getting populated, but "First Name" and "Last Name" are not. In the logs I can see it:

 [isNewUser] =&gt; 1
 [fullName] =&gt; aaa bbb
 [firstName] =&gt; aaa
 [lastName] =&gt; bbb


But the First Name &amp; Last Name fields in the user account tab are not getting populated.
From the onSaveUser event docs, there are two parameters that are passed to everyone listening.  One is isNewUser, which you're accessing correctly: $event-&gt;params['isNewUser'].  But the other is user, which is a full-blown UserModel object that you can access the properties of.

But onSaveUser isn't the event you want, since you want to make changes to the user before they've been saved.  You want onBeforeSaveUser, which has the exact same parameters.

Having said that, names are tricky things around the globe.  I highly recommend reading this article on falsehoods that programmers believe about names.

Here is some code that should work for the most basic use cases.

craft()-&gt;on('users.saveUser', function (Event $event) {

    // Only do this for new users.
    if ($event-&gt;params['isNewUser'])
    {
        $fullName = craft()-&gt;request-&gt;getPost('fields.fullName');

        // Make sure this isn't a user being saved from the control panel.
        if ($fullName)
        {
            $name = explode(' ', $fullName);

            // No spaces, it could be Madonna or Cher.
            if (count($name) == 1)
            {
                $firstName = $name[0];
                $lastName = '';
            }
            // It's a "normal" first and last name.
            else if ($count($name) == 2)
            {
                $firstName = $name[0];
                $lastName = $name[1];
            }
            else
            {
                // The first element is the first name. Combine the rest into a last name separated by spaces.
                $firstName = array_pop($name);
                $lastName = implode(' ', $name);
            }

            // Grab the user.
            $user = $event-&gt;params['user'];

            $user-&gt;firstName = $firstName;
            $user-&gt;lastName = $lastName;
        }
    }
}


Note that UserModel already has a getFullName method that does some basic logic combining the firstName and lastName properties.