ziu

each user allowed to add only one page under a parent template

Recommended Posts

hi, just created a parent page and under this i want a user who is logged in to create only one page, not more than that. how can i do this.

thanks

Share this post


Link to post
Share on other sites

You will need to use a hook, maybe in ready.php. Here's some code to get u started (unstested and written in a hurry).

// I can't remember if 'child' will get unpublished and/or hidden pages
// you might need to perform other checks (user logged in? => $user->isLoggedin())
$usersChildPage = $parentPage->child("created_users_id={$user->id}");
if($usersChildPage && $usersChildPage->id) {
	// this user already has a child page; do something else
}

 

  • Like 1

Share this post


Link to post
Share on other sites

Another approach is to not allow users to create pages at all, but rather automatically create a single unpublished page for each user in a hook at the time the user is created. Then each user can populate and publish their page if they wish.

  • Like 4
  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, Robin S said:

Another approach is to not allow users to create pages at all, but rather automatically create a single unpublished page for each user in a hook at the time the user is created. Then each user can populate and publish their page if they wish.

Yeah, this approach is better. 

@ziu

There's various examples in the forum regarding Robin's suggested approach. Just can't find them now.

  • Like 1

Share this post


Link to post
Share on other sites

@adrian i am still not able to figure it out, can u tell me how can create a page like 'profile' so that when user who logs in can have this page's shortcut on their screen and can just fill this page.

Share this post


Link to post
Share on other sites

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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ziu
      Hi i created a custom admin page and i  just want to know is there a module  or any way to show a user only those pages under subpages of a page in tree which he has created. please help.
    • By ziu
      I have created a website that has a login and register feature.
      i used ryan's login register module.
      but now i want the logged-in user to add a page e.g. Add Property this page will have custom fields which logged in user will fill. but user can add only single. and he/she can update/edit this page only.
      I need your help guys in achiveing this.
      Thanks in advance.
      Any help will be appreciated.
    • By ziu
      Hi everyone,
      I am new to processwire, but really  appreciate the way  its works. Thank you Ryan.
      I need your help guys, any help would be  appreciated, as i am searching the forum since last 1 month. but couldn't found out how to achieve.
      My issue is as my user registers on my website, it will be assigned a role. eg  Register
      but what i want to achieve is that after login i want  user to have edit profile , logout and Add Page. But i want user to add only one time, only single page can be post by him.
      if user adds the page, and login into  account it must show edit page.
      Please help me guys.
    • By benbyf
      Hi!
      Implemented Ryan's blog template to kickstart a site I was making for my own business and can't get to grips with the Abstraction of the RSS feed in it.
      site: blog.eulergy.com/
      rss: http://blog.eulergy.com/categories/resources/rss
      notice that the dates are running in the wrong order old to new and not newest first. Anyone able to illustrate how one might change that in the blog template?
      Thanks,