2

Is there a way to create a front-end form that would allow a user with appropriate privileges (Register users) to register new users?

2

What you could try to do, though I don't know if this will work, is use the same form that craft CP uses in the backend. Using Google f12 I managed to find this:

<form id="userform" class="pane" method="post" accept-charset="UTF-8" autocomplete="off" data-saveshortcut="" data-saveshortcut-redirect="users/{id}">
<input type="hidden" name="action" value="users/saveUser">
<input type="hidden" name="redirect" value="users">
{{ getCsrfInput() }}
//Forms you want user to input
<input type="submit" class="btn submit" value="Save">
</form>

The above form is the same form that Craft uses natively to register users so it might work. Obviously, your admins will require the privileges to register users.

  • Good thought. I'll give that a try, thanks. – Philip Jones Nov 27 '17 at 16:35
1

Definitely doable with a custom plugin.

Your front-end form could be similar to the standard front-end user registration form (https://craftcms.com/docs/templating/user-registration-form), but instead you'd point the form action to your plugin's controller.

From that point, you can do pretty much whatever you want with the POST'd data using Craft's service layer API. i.e. check existing user's permissions, save user, etc.

  • Okay, bear with me. If a non-logged-in user can submit a form to create a new user and all the associated actions that occur as a result, why can't that exact same process be done by a logged-in user (assuming they have the appropriate permissions)? – Philip Jones May 5 '17 at 21:15
  • They can? I feel like maybe I'm not understanding the problem. – Brad Bell May 5 '17 at 21:32
  • Provided I have turned on "Allow public registration?" in user settings, I can create a user registration form using the example provided in the Craft docs. Using this form, a user who is not logged in can register for an account. Once that form is submitted, the user is sent an activation email. Once they click the link in the activation email, their account is activated and they are automatically assigned to the group specified in the "Default User Group" dropdown in user settings. – Philip Jones May 5 '17 at 22:27
  • I just want to be able to do the same thing, but instead of it being initiated by a not-logged-in user, I want it to be initiated by an admin who has "Register users" permissions. – Philip Jones May 5 '17 at 22:29
  • Right... so your plugin would need to override whatever steps/controller actions of the user registration workflow as necessary. In your case, specifically actionVerifyEmail. – Brad Bell May 7 '17 at 23:36

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.