Custom Field in a New Tab - Please help!

Discussion in 'Customization & add-ons' started by lucas4ce, Jan 15, 2011.

  1. lucas4ce

    lucas4ce New Member

    Joined:
    Dec 12, 2010
    Messages:
    3
    I need to add a lot of custom fields for my members to change as they wish. I can add these using CP->Add Field and everything works fine on my site. But the additional fields are placed in the "Edit Profile" tab.

    What I want to do is have these fields in a "Custom Data" tab on the member.php login page.

    What I've managed to do so far:
    1. Added my "Custom Data" tab by inserting this line into the init() function code in the amember/tabs.inc.php page
      Code:
      $this->add(new TabMenu_Tab('Custom Data','customdata.php',null));
    2. Created a file amember/customdata.php containing this code
      Code:
      <?php
      include('./config.inc.php');
      $t = & new_smarty();
      $_product_id = array('ONLY_LOGIN');
      require($config['plugins_dir']['protect'] . '/php_include/check.inc.php');
      $t->display('eurocode.html');
      ?>
    3. Created a file amember/templates/customdata.html based on the profile.php page, with some initial information with this code
      Code:
      {assign var="title" value='Custom Data'}
      {include file="header.html"}
      <div class="backend-wrapper">
      {include file="member_menu.inc.html"}
      {include file="error.inc.html"}
      <form name="signup" method="post" action="{$smarty.server.PHP_SELF|escape}">
      <table class="vedit" width="100%">
      <tr>
          <th class="headrow" colspan="2">STEEL EUROCODE 3: EN1993</th>
      </tr>
      <tr>
          <th style='width: 40%'><b>ψ<sub>0,Wind</sub></b><br />
          <div class="small">EN 1990:2002 cl.A1.2.2<br />Factor for combination value of variable action: Wind</div></th>
          <td><input type="text" name="fieldname" value="{$user.data.psi0wind|escape}" size="5" /></td>
      </tr>
      </table>
      </form>
      </div>
      {include file="footer.html"}
    The field $user.data.psi0wind is a real custom field I have created, and used successfully from the "Edit Profile" tab.

    The bits I need help with:
    1. How do I correctly link my $user.data information to this new tab so that values from the users database appear in the text box? At the moment this text box is blank, i.e. it is not showing the default for this field.
    2. How do I add a save button similar to the one at the bottom of the "Edit Profile" page, that will save any updates that members make?

    Any help would be greatly appreciated :)
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    1. Add this code to your customdata.php file:
    $t->assign("user", $db->get_user($_SESSION[_amember_id]));
    2. This will require modifications in customdata.php as well.
    You need to add code that will handle your form submit, check user input and then update user's profile.
    Profile can be updated this way:
    $user = $db->get_user($member_id);
    $user['data']['field'] = 'newvalue';
    $db->update_user($member_id, $user);
  3. lucas4ce

    lucas4ce New Member

    Joined:
    Dec 12, 2010
    Messages:
    3
    Excellent thank you!

Share This Page