Jump to content
DaveP

Custom User Fields

Recommended Posts

Forgive me if this has been answered before, but the threads I have read have talked about upcoming features, which I am not sure whether they are available or not.

What I am trying to do is have quite a comprehensive user profile available (I am attempting to build a simple forum with PW). I can sort of get it to work with a second user profile table, but there is always the possibility that the two will get out of step.

Is there a way of adding fields to the existing 'users' pages? (Any other tips would be most welcome.)

Share this post


Link to post
Share on other sites

Dave,

You can add whatever fields you want to the user template. I'm building a fairly complex user profile setup as well.

Go to: Setup > Templates, at the top of the page open the "filters" area and enable "show system templates".

Now you can add any of your fields to the user template.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks, Renobird. I hadn't noticed the 'filter' control!

(As always, PW already has an easy way of doing something I was making difficult for myself.)

Share this post


Link to post
Share on other sites

Supplementary question - what's the best way to have some information from a user profile available for public viewing (ie to allow 'guest' viewing rights to some information)?

Share this post


Link to post
Share on other sites

Hi Dave,

Unless there's some method of showing profile info that I'm not aware of (entirely possible), you can choose to display or not display any profile information in your template.

<h2><?=$user->name?></h2>
<p><?=$user->job_title?></p>
<p><?=$user->bio?></p>
<p><?=$user->email?></p>

Share this post


Link to post
Share on other sites

This comes back to everything in PW being a page, even users.

For example, I can fetch myself using $pete = $pages->find('template=user, name=pete, include=hidden');

You might want to check that field name though since I'm on my phone, but I think that's right anyway. Either way the users section is hidden so you will need that bit on the end I think.

Share this post


Link to post
Share on other sites

Pete is on the right track, but I think this is what you want instead:

$pete = $users->get('name=pete'); 

or this also works:

$pete = $users->get('pete'); 
  • Like 1

Share this post


Link to post
Share on other sites
<?php foreach($users->find($item->writer) as $usr); ?>

Odd thing that my custom field not showing when using print_r or var_dump, but still works if using $usr->customfield. Sorry about this post, I had a question, but found an answer already. Can't delete my own posts.

Share this post


Link to post
Share on other sites

Hello,

I have created a standard field type as userphone , then I added this field to the User template. I created a phone field type using Phone Field module. I added this field to the User template also.

image.thumb.png.f40f3d23d3f8849fdf15e13a06ef63b6.png

Now I used the below to create a test user

 $u = new User();
$u->of(false);
$u->name = "saarun";
$u->email = "saarunthomas@example.com";
$u->pass = "123456";
$u->Phone = 9446196667;
$u->userphone = 9446196667;
$u->headline = "hello there";
$u->paid=1;
$u->addRole("registered");
$u->save();
$u->of(true);

and I tried to out put as below

     $item = $users->get("saarun");
echo $item->email;
echo $item->Phone;
echo $item->paid;
echo $item->headline;
echo $item->userphone;

and I got the output a below.  Neither the userphone value nor the Phone value are output ... what am I doing here wrong  ? pls help

 

image.png.eee59c5c952dd521d71cb1dd8d23cd22.png

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...