Adding and Accessing Custom Fields in Registration in CS2007

rated by 0 users
This post has 6 Replies | 3 Followers

Not Ranked
Posts 10
Points 110
maksum Posted: Tue, Apr 1 2008 6:34 PM

I know there are a number of posts on this, but so many of them intermingle information concerning different versions of Community Server.  Hopefully someone can help me with some specific information.

I'm trying to add a custom field to the registration form... specifically a "How did you hear about this site?".  Most of the information I used to got as far as I did came from this thread:

http://communityserver.org/forums/t/468133.aspx?PageIndex=1

This is what I have done so far...

------------------------------------------------------

communityserver.config
within the <CommunityServer> tags I added:
<ExtendedUserData>
  <add name = "howdidyouhear" />
</ExtendedUserData>

ControlPanel/Membership/UserEdit.aspx
Added:
<tr>
  <td class="CommonFormFieldName" width="45%">
    How Did You Hear About This Site?
  </td>
  <td class="CommonFormField">
    <asp:TextBox  id="howdidyouhear" columns="40" runat="server" />
  </td>
</tr>

Themes/leanandgreen/User/createuser.aspx
Added:
<tr>
  <td align="right">
    How Did You Hear About This Site?
  </td>
  <td>
    <div class="CommonFormField">
      <asp:TextBox  id="howdidyouhear" columns="40" runat="server" />
    </div>
  </td>
</tr>

Themes/leanandgreen/user/edituser.aspx
Added:
<p>
  <h3 class="CommonSubTitle">How Did You Hear About This Site?</h3>
  <asp:TextBox  id="howdidyouhear" columns="40" runat="server" />
</p>

------------------------------------------------------

So it seems that portion does what it is supposed to.  However, I'd really like to be able to access a user from the admin panel and see what they put for this new field.  If anyone can tell me how to show that information (probably on the UserEdit.aspx page) that would be SO VERY helpful.  I tried pasting in some bits of code they had on that thread I referenced above, but it just breaks my site.

Thanks in advance!

Mike


Top 10 Contributor
Posts 3,637
Points 54,925
TelligentSupportTeam

In the Control Panel/Membership/UserEdit page, you'll have to add a new textbox control with a specified ID.  You'll then have to add some code to load and save the data - I've used the folowing code to do a similar thing (where textbox is the name of your textbox).

<script runat="server">
 
 protected override bool Update(User userToEdit)
 {
  userToEdit.SetExtendedAttribute("howdidyouhear", textbox.Text);
  return base.Update(userToEdit);
 }

 protected override void OnLoad(EventArgs e)
 {
  /* We only want to load user data if the page is not a post back
   * Ideally we'd add this to the bind method but that would involve
   * Making changes to the core code, and as it's only an admin page
   * this hack is perfectly suitable */
  if (!Page.IsPostBack)
  {
   User userToEdit = CommunityServer.Users.GetUserWithWriteableProfile(CSContext.Current.UserID, null, false);
   textbox.Text = userToEdit.GetString("howdidyouhear", string.Empty);

  }
  base.OnLoad(e);
 }
 
</script>

 

Community Server Documentation please rate articles you read

Nintendo Wiikly | My Blog

  • | Post Points: 20
Not Ranked
Posts 10
Points 110
maksum replied on Wed, Apr 2 2008 1:17 PM

Thanks for your reply.  So now in ControlPanel/Membership/UserEdit.aspx I have this:

-------------------------------

<tr>
  <td class="CommonFormFieldName" width="45%">
    How Did You Hear About This Site?
  </td>
  <td class="CommonFormField">
   
    <script runat="server">
     protected override bool Update(User userToEdit)
     {
      userToEdit.SetExtendedAttribute("howdidyouhear", myhowhearbox.Text);
      return base.Update(userToEdit);
     }
     protected override void OnLoad(EventArgs e)
     {
      /* We only want to load user data if the page is not a post back
       * Ideally we'd add this to the bind method but that would involve
       * Making changes to the core code, and as it's only an admin page
       * this hack is perfectly suitable */
      if (!Page.IsPostBack)
      {
       User userToEdit = CommunityServer.Users.GetUserWithWriteableProfile(CSContext.Current.UserID, null, false);
       myhowhearbox.Text = userToEdit.GetString("howdidyouhear", string.Empty);
      }
      base.OnLoad(e);
     }
    </script>
   
    <asp:TextBox  id="myhowhearbox" columns="40" runat="server" />
  </td>
</tr>

-------------------------------

It is not breaking the site now, which is great... but going into admin it's not populating that text box with the information.  I suppose there is still a possiblity that the information was never correctly collected in the first place.  Do you know if there is a way to check that, or do you see something I'm just doing wrong here?

Thanks so much.


  • | Post Points: 35
Top 500 Contributor
Posts 48
Points 760

 Is the process much different in cs 2008 (as far as what files need editing)? I think I've changed at least 5...

Top 10 Contributor
Posts 3,637
Points 54,925
TelligentSupportTeam

Depending on how you are using your additional user information, the files you'll want to edit are

  • The Create User page to capture information on user registration (~/Themes/YOUR THEME/User/CreateUser.aspx)
  • The Edit Profile page if you want to allow users to change or add data after their user has been created (~/Themes/YOUR THEME/User/CreateUser.aspx)
  • The User Edit page in Control panel if you want to allow users to view / edit additional information provided by the user (~/ControlPanel/Membership/UserEdit.aspx)

For the Create User and Edit Profile Pages, you'll want to implement your custom functionality in the form of a profile subform.  In the Control Panel Edit User page, you'll want to manually add controls to the page, and bind that data in the Bind() method, and Save that data in the Update(User userToEdit) method.  If you have the SDK, you'll want to make those changes in the UserEdit.aspx.cs file, otherwise you'll want to override said methods in the aspx page to do your additional functionality, before calling the base method.

Community Server Documentation please rate articles you read

Nintendo Wiikly | My Blog

  • | Post Points: 5
Top 10 Contributor
Posts 3,637
Points 54,925
TelligentSupportTeam

Sorry maksum, i didn't see your response.  Have you managed to resolve your issue or are you still having problems?

If you're still unsure if you're collecting the data correctly on Registration, Try changing the reason the user signed up in the Control Panel, save the user then reload the page (make sure your browser loads the page again as opposed to loading the page from the cache).  If the change you applied above appears, then the problem is likely to be in your data collection, othrewise the problem is likely to be with the Control Panel modifications.

Community Server Documentation please rate articles you read

Nintendo Wiikly | My Blog

  • | Post Points: 20
Not Ranked
Posts 10
Points 110
maksum replied on Mon, Jun 9 2008 11:50 AM

You know... been a while since I've touched this.  I was contracting with a company and I believe my contract for this particular job wrapped up and they took the remaining issues internal.  If they contact me to jump back on I'll see where they are.  Thanks for the reply.


  • | Post Points: 5
Page 1 of 1 (7 items) | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com