Jump to content

Creating a page when a user registers


Recommended Posts


I'm creating a site where people can vote on dogs.

To start with, I need the dog owners to register and then upload text, images, and videos about their dog. What I thought I could do is to create a page when the user registers. The page would be unique by using the member ID. So I would end up with:

     - Members

Then each member page would have 1 or more children which would be the dogs that they have added.

I just wanted to ask if that is a good way of doing things or if there's maybe a much simpler way of doing this.

Thanks in advance for any advice.

Link to comment
Share on other sites

I would probably prefer to put my users under the Members page directly. That way you would still end up with your suggested page tree, but those pages would actually be the users and there would be no need to maintain a relationship between users and their pages. Have a look at this blog post for a tutorial: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users

  • Like 7
  • Thanks 1
Link to comment
Share on other sites

I think I've done that correctly. Please see attached.

user_1 has an id of 57.
owners has an id of 58.

So I've added

$config->userTemplateIDs = array(3, 57);
$config->usersPageIDs = array(29, 58);

to config.php.




Link to comment
Share on other sites

12 hours ago, Dean said:

owners has an id of 58.

$config->usersPageIDs = array(29, 58);

I think this may be the problem. 58 seems to be the ID of your template, but the config setting must be supplied with the ID of the page. In your example from the opening post, that page is “Members”, so you want to change Members’ template to owners (58) and put Members’ ID into $config->usersPageIDs. It’s probably a four digit number rather than a double digit template ID.

  • Like 3
Link to comment
Share on other sites

Sorry, one last question. How can I now create my new user with the new template and new parent? It doesn't seem to like this:

wire()->addHookBefore('LoginRegister::createdUser', function($event) {
	$u = $event->arguments[0];
	$u->parent = 1083; // set new parent


Link to comment
Share on other sites

Uh, I’ve never used LoginRegister, but some pointers:

  • Not sure if you can use the hook arguments that way. I always use $event->arguments(0) (it’s a method).
  • You should probably hook createUserReady instead. This fires immediately before the user is saved, so you don’t need to do it.
  • You aren’t setting the user’s template to 57.


  • Like 1
Link to comment
Share on other sites

It’s both! A user is a special kind of page. If you look at ProcessWire’s source code, you will see that the User class extends the Page class. At first it’s a little confusing, but it’s pretty cool because you roughly always deal with the same (or quite similar) things in PW. For example, you can find users using selectors just like finding pages of content. You can also modify and save them the same way, as you did in your hook. And if you want to add a field to your user (maybe a profile picture) you know just what to do: create a field and add it to the template, just like any other content.

  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...