Jump to content

Recommended Posts

Posted

Hello,

I'd like to add the user who wrote the post to the page data (either guest, or the logged in user), this is the code I'm currently using

$form = $modules->get('FormTemplateProcessor');
$form->template = $templates->get('annuncio'); // required
$form->requiredFields = array('title', 'body');
$form->parent = $page->parent; // optional, saves form as page
echo $form->render(); // draw form or process submitted form

Btw, using this code I get all the fields I put in the template, so rendering the user field generates a dropdown selectable list of users...

Thanks for any advice!

Posted

ProcessWire already keeps a references to the users that created the page and last modified the page, so you don't need to maintain that separately yourself. They are present in $page->created_users_id and $page->modified_users_id (to get the ID) or $page->createdUser and $page->modifiedUser to get the User objects. 

  • Like 1
Posted

Thanks Ryan!

I'm wondering how to query the pages so to find all pages with user = loggeduser... I'm trying this one:

$annunci = $pages->find("parent=/bacheca/, sort=-date, title!=new, limit=20, createdUser=$user->id");

But it doesn't seem to work.

Thanks!!

Posted

$page->createdUser is a method to get the user object and has nothing to do with the field $page->created_users_id you can use in selectors.

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.
×
×
  • Create New...