Results 1 to 2 of 2

Thread: Adding Extra Profile Fields

  1. #1
    Former lead dev Nick's Avatar
    Join Date
    Jun 2009
    Location
    Kakamigahara, Japan
    Posts
    2,858
    Blog Entries
    88
    Thanks
    482
    Thanked 806 Times in 526 Posts

    Default Adding Extra Profile Fields

    User profiles in the Users plugin have been designed to make it as easy as possible to customize them, either with your own plugins or with a few template edits. Here's a quick example of how you could add a "website" field to a profile page:

    1. Get the templates

    As always, if you want to edit plugin templates, you should move them to your own theme folder first, so copy profile.php and edit_profile.php from

    /content/plugins/users/templates/

    to

    /content/themes/YOUR_THEME/

    2. Add an input box

    Open edit_profile.php and scroll down to where there's a comment "Add your own profile fields here."

    Above that, add

    PHP Code:
    <tr><td>Website: </td><td><input type="text" name="website" value="<?php echo $profile['website']; ?>"></td></tr>
    If you save and look at the profile edit page in your account, you should see a new field where you can enter your website url.

    3. Save the website url

    To save that url when you click update, look near the top of edit_profile.php for a comment like "Add your own $profile['something'] stuff here."

    Above that, add:

    PHP Code:
    $profile['website'] = $h->cage->post->testUri('website'); 
    Note: testUri is an Inspekt filter. See other filters here.

    4. Show the website url in the profile

    Open profile.php and add the following wherever you want to show the website:

    PHP Code:
        <a href="<?php echo $profile['website']; ?>">
            <?php echo $profile['website']; ?>
        </a>
    Finished.

    You'll probably want to tidy that up with some extra HTML and/or CSS, but that's the basic process.

  2. #2
    Former lead dev Nick's Avatar
    Join Date
    Jun 2009
    Location
    Kakamigahara, Japan
    Posts
    2,858
    Blog Entries
    88
    Thanks
    482
    Thanked 806 Times in 526 Posts

    Default Undefined Index Errors

    If you enable Debug mode in Admin -> Settings, you will probably get "undefined index" errors for fields that you haven't saved yet.

    To fix those, use something like this before the line where the error is found:

    PHP Code:
    <?php if (!isset($profile['field_name'])) { $profile['field_name'] = ''; } ?>
    You will probably need that for each field in both the users_profile and users_edit_profile templates.

  3. Thanked by:


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [Done] Profile page
    By runnertalk in forum Plugin Suggestion Box
    Replies: 5
    Last Post: 10-08-2009, 03:46 AM
  2. [Docs] Adding Permissions
    By Nick in forum Developing Plugins
    Replies: 0
    Last Post: 09-27-2009, 04:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •