I'm writing a customer portal plugin, utilizing Crafts user registration form: https://craftcms.com/docs/templating/user-registration-form

{# User registration form: #}
<form method="post" accept-charset="UTF-8">
    {{ getCsrfInput() }}
    <input type="hidden" name="action" value="users/saveUser">
    <input type="hidden" name="redirect" value="">

    {# What do I add / change ? #}

    {# ... #}

My plugin has two different types of account profile records, .._OrganizationProfileRecord and .._UserProfileRecord. What I want to do is send a variable to the onSaveUser event handler in my plugin main class, to tell it what type of user was just saved ("org" or "user"), and then take appropriate actions, i.e. create either an organization or user profile.

class myPortalPlugin extends BasePlugin
    public function init()
        craft()->on('users.onSaveUser', function(Event $event)
            $craftUser = $event->params['user'];
            $isNewUser = $event->params['isNewUser'];

            if ($isNewUser)
                // Check if user is an organization or a regular user, and
                // create the appropriate profile record.

                // How do I check?

                // ...

    // ...


  1. How would I go about passing data/variable from the form to the onSaveUser event handler?
  2. Is there a better / more convenient way to do this?

Many thanks in advance for any help you can provide in this matter! bowing


1 Answer 1


I found a solution. Though I am not sure if this is the best way to go about it, but here's what I did:

<input type="hidden" name="userType" value="org">

was added to the register form, and ...

$userType = craft()->request->getPost('userType');

if ($userType == 'org')
    // ...

was added to the onSaveUser event handler function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.