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

XF 1.0 How to create a new field in the member profile

Discussion in 'XenForo Questions and Support' started by AndreaMarucci, Oct 17, 2011.

  1. AndreaMarucci

    AndreaMarucci Well-Known Member

    In the VB4 forum, before the switch, I had one custom field in the member profile page that every user used to put in the real name.

    I'm searching for something to let users put some extra contact info in their profiles (like telephone number, email, real name and so on) but I would like that these info are only visible to a specific usergroup (registered members that have payed the annual quota). For now it suffice to have a field for the real name but if I could use the same system to put in also the phone number or the email, should be good.

    I think that this could be done modifying one template but I really don't know how and where...

    Anyone can suggest how I can do that?
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Profile fields don't have group permissions.

    A template edit would work even though it's not an ideal solution to maintain privacy of those fields. Where do you want those fields to be conditionally displayed?
     
  4. AndreaMarucci

    AndreaMarucci Well-Known Member

    Oh I really don't know. I think that the easier way to implement it, the better. I don't want to suggest something that's too complicated...
     
  5. AndreaMarucci

    AndreaMarucci Well-Known Member

    Hello Jake, have you maybe found a little trick to do that? Is it possible?
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I can come up with template code if you tell me where you want those fields to be conditionally displayed.
     
    wickedstangs likes this.
  7. AndreaMarucci

    AndreaMarucci Well-Known Member

    Thanks!! Should be possible to put them under Active Member like in the example below?

    Active Member, Male, 48, from Como - Italy
    Name: Andrea Marucci - Telephone: 123-123456 - Email: name@domain.com

    The row above should be displayed only to the members of group X

    Schermata 10-2455858 alle 18.33.08.png
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Admin CP -> Appearance -> Templates -> member_view

    Find the userBlurb and add the red code:

    Code:
    				<p class="userBlurb">
    					{xen:helper userBlurb, $user}
    					<xen:if is="{xen:helper ismemberof, $visitor, 5}">
    						<div style="font-size: 11px;">
    							Name: {$user.customFields.name} - Telephone: {$user.customFields.phone} - Email: {$user.email}
    						</div>
    					</xen:if>
    					<xen:if is="{$canCleanSpam}"><a href="{xen:link spam-cleaner, $user}" class="deleteSpam OverlayTrigger">{xen:phrase spam_cleaner}</a></xen:if>
    				</p>
    
    You need to fill in the blue pieces which are the privileged groupid and the field_ids for the custom fields for name and phone number.
     
  9. AndreaMarucci

    AndreaMarucci Well-Known Member

    Thanks Jake, two questions

    1 - If I would need more than one usergroup, which is the correct syntax. I would need groups ID 12,3,4
    2 - Where the user is supposed to fill the custom fields name and telephone?

    I've pasted the code and the email appears but the other two are blank spaces.

    Thanks...
     
  10. AndreaMarucci

    AndreaMarucci Well-Known Member

    I've to add that I'm using XF 1.0.4 and not 1.1
     
  11. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    There is short syntax for checking multiple primary groups:

    Code:
    				<p class="userBlurb">
    					{xen:helper userBlurb, $user}
    					<xen:if is="in_array({$visitor.user_group_id}, array(12,3,4))">
    						<div style="font-size: 11px;">
    							Name: {$user.customFields.name} - Telephone: {$user.customFields.phone} - Email: {$user.email}
    						</div>
    					</xen:if>
    					<xen:if is="{$canCleanSpam}"><a href="{xen:link spam-cleaner, $user}" class="deleteSpam OverlayTrigger">{xen:phrase spam_cleaner}</a></xen:if>
    				</p>
    
    But to check both primary and secondary you have to use the long form:

    Code:
    				<p class="userBlurb">
    					{xen:helper userBlurb, $user}
    					<xen:if is="{xen:helper ismemberof, $visitor, 12} OR {xen:helper ismemberof, $visitor, 3} OR {xen:helper ismemberof, $visitor, 4}">
    						<div style="font-size: 11px;">
    							Name: {$user.customFields.name} - Telephone: {$user.customFields.phone} - Email: {$user.email}
    						</div>
    					</xen:if>
    					<xen:if is="{$canCleanSpam}"><a href="{xen:link spam-cleaner, $user}" class="deleteSpam OverlayTrigger">{xen:phrase spam_cleaner}</a></xen:if>
    				</p>
    
    You need to create custom profile fields for the name and phone number. Custom profile fields are only in version 1.1.
     
  12. kkm323

    kkm323 Well-Known Member

    I did that with a line edit using paul importer. I pull up the content of that custom field into the About me ...
    add this code change the #3 with your field number

    Before:

    Code:
            switch ($user['usergroupid'])
    
    I did this way back...
    so please try this in a test forum & back-up your database.
     
    Fuhrmann likes this.
  13. AndreaMarucci

    AndreaMarucci Well-Known Member

    Thanks Jake. I'll wait for the final 1.1 to upgrade and use this feature...
     
  14. AndreaMarucci

    AndreaMarucci Well-Known Member

    Just to let you know that I've tested this on my test board with 1.1 and it work as expected, thank you very much :)
     

Share This Page