1

Is there a way to return a user model entry, userid, or some other identifier (and/or variables in general) from a successful registration form submission using the hidden redirect parameter?

In the docs for action/saveUser I see some mention of {id} in the redirect string, but I'm not exactly sure sure how this works (or if it's even related).

      if (isset($_POST['redirect']) && mb_strpos($_POST['redirect'], '{userId}') !== false)
      {
           craft()->deprecator->log('UsersController::saveUser():userId_redirect', 'The {userId} token within the ‘redirect’ param on users/saveUser requests has been deprecated. Use {id} instead.');
           $_POST['redirect'] = str_replace('{userId}', '{id}', $_POST['redirect']);
      }

The reason I ask is that I am creating a multipart form that relies on the values of the previous form submission to continue (starting with user account registration). I essentially want to redirect back to the form, fill out the next part, submit, redirect back to form, fill out next, etc. (controlling the workflow with javascript or twig). FYI, using impersonate() will not work for me in this case, because user must be admin, or in a custom 'manager' group.

As a side question, I also see craft()->userSession->setNotice(Craft::t('User saved.')); used throughout the saveUser controller. Is there a corresponding getNotices() similar to getErrors() or some way to retrieve these on the front-end?

1 Answer 1

1

In your redirect hidden input in your form, add an {id} tag like so:

<input type="hidden" name="redirect" value="nextStep/{id}">

And that will be populated with the newly created user's userId.

Is there a corresponding getNotices() similar to getErrors() or some way to retrieve these on the front-end?

You'd have to duplicate the code that the control panel uses to retrieve the notices on the front-end of the site.

4
  • Thank you Brad! Half way there. value="nextStep/{id} leads me to a page not found... I assume that I would need to create a route for that to work? If I use value="nextStep.html?id={id}" then I can retrieve the id fine. On step 3, however, I would need to return the entryId from step2 and the userId from step 1 — possible? or are we now in the land of plug-ins with cache, session storage, etc? Commented Sep 25, 2014 at 23:33
  • yeah, you'd need a route or just use it in the querystring. I'm not sure what your step 2 and step 3 are posting to. Probably worth a new question with some more details explaining what you're trying to do.
    – Brad Bell
    Commented Sep 26, 2014 at 1:19
  • Step 1 registers a user; Step 2 creates a channel entry to 'accounts' related to user; step 3 creates a channel entry to 'subscriptions' related to 'accounts'. Basically, just want to know if there is way to pass some variables through action/saveUser and action/saveEntry? Sounds like it might be time to learn how to write my own controllers - wish me luck. And thanks again! Commented Sep 26, 2014 at 1:50
  • Yup... a plugin would probably simplify things. Good luck!
    – Brad Bell
    Commented Sep 26, 2014 at 4:17

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.