Jump to content

FormTemplateProcessor adding user to post


Manaus
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...