1

I am using business logic plugin to tap into save user event and create some profile field values.

public function init(){
    parent::init();

    craft()->on('users.saveUser', function(Event $event) {

    }
}

On save user returns a success object. I want to return more user profile data to the page on success.

In the save User function I have tried:

 if (craft()->request->isAjaxRequest())
 {
     $return = array(
         'success' => true,
         'errorCode' => 1,
         'uid' => $user->id,
         'urn' => $URN
     );

     return json_encode($return);
 }

but I still get the usual response of success and user id. How do i get a thank you 'page' into the process so I can feedback to the user?

  • That event you're using allows you do run code when a user is saved/updated, whether that be in the front-end or in the Control Panel. Are you updating the user on the front-end? – Brad Apr 25 '17 at 20:09
  • Its incomplete. Its front end registration and code contains: if (craft()->request->isSiteRequest()) {} and if ($event->params['isNewUser']) { – joomkit Apr 25 '17 at 20:17
  • if you're doing front-end, just submit to the saveUser endpoint in the craftcms docs for registration w/ a redirect hidden input set, once it redirects to the place you set it to, you can display the user's info there, using the currentUser object, for example: currentUser.email, etc. – Brad Apr 26 '17 at 14:07
  • Its an ajax user registration..... – joomkit Apr 26 '17 at 15:08
  • One option is to hack the UsersController.php file, around line 1060 to include additional data on the return. – Brad Apr 26 '17 at 15:49
1

Instead of listening to the onSaveUser event, I'd update my user save form on the front-end to point to a controller's action in my plugin.

You can run similar logic to what Craft's UsersController->actionSaveUser() is doing and return any custom JSON encoded data you want back to your template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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