1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Docs] Adding Extra Profile Fields

Discussion in 'Design and Layout' started by Nick, Nov 18, 2009.

  1. Nick

    Nick Well-Known Member

    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:
    <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:
    $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:
        <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. Nick

    Nick Well-Known Member

    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:
    <?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.
     
    daveryder likes this.

Share This Page