FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups  Who is OnlineWho is Online   Join! (free) Join! (free)  
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  • Welcome
  • Guest

Hiding profile fields in UCP in phpbb3

 
Post new topic   Reply to topic    myfreeforum.org Forum Index -> Wiki Guides
View previous topic :: View next topic  
Author Message
Zudane
Moderator
Moderator
FLAG

Virtual Cash: 21140

Joined: 10 May 2008
Posts: 2040



Add Karma

rated by 24 members
Add Comment
Show Comments

Harsh Reality
online/offline
PostPosted: Sat Aug 22, 2009 9:53 pm    Post subject: Hiding profile fields in UCP in phpbb3  Reply with quote

As you may know, there is an option for custom profile fields to be hidden from the User Control Panel when creating a profile field.  This works great - as long as the user isn't a moderator or admin - then it's useless.

To hide the profiles fields from everybody (regardless of whether or not it's checked in the Admin Control Panel), follow this guide:

Go into the ACP, and edit the template ucp_profile_profile_info.html *

Near the bottom you should find this:

Code:
<!-- BEGIN profile_fields -->
   <tr>
      <td class="row1" width="35%">


         <b class="genmed">{profile_fields.LANG_NAME}: </b>
         <!-- IF profile_fields.S_REQUIRED --><b>*</b><!-- ENDIF -->
         <!-- IF profile_fields.LANG_EXPLAIN --><br /><span class="gensmall">{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF -->
      </td>
      <td class="row2">{profile_fields.FIELD}<!-- IF profile_fields.ERROR --><br /><span class="gensmall error">{profile_fields.ERROR}</span><!-- ENDIF --></td>
   </tr>
<!-- END profile_fields -->


This code is what sets the profile fields up.  Copy everything between the BEGIN and END tags and paste it again, you should then end up with two blocks of that code like this:


Code:
<!-- BEGIN profile_fields -->
   <tr>
      <td class="row1" width="35%">
         <b class="genmed">{profile_fields.LANG_NAME}: </b>
         <!-- IF profile_fields.S_REQUIRED --><b>*</b><!-- ENDIF -->
         <!-- IF profile_fields.LANG_EXPLAIN --><br /><span class="gensmall">{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF -->
      </td>
      <td class="row2">{profile_fields.FIELD}<!-- IF profile_fields.ERROR --><br /><span class="gensmall error">{profile_fields.ERROR}</span><!-- ENDIF --></td>
   </tr>
   <tr>
      <td class="row1" width="35%">
         <b class="genmed">{profile_fields.LANG_NAME}: </b>
         <!-- IF profile_fields.S_REQUIRED --><b>*</b><!-- ENDIF -->
         <!-- IF profile_fields.LANG_EXPLAIN --><br /><span class="gensmall">{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF -->
      </td>
      <td class="row2">{profile_fields.FIELD}<!-- IF profile_fields.ERROR --><br /><span class="gensmall error">{profile_fields.ERROR}</span><!-- ENDIF --></td>
   </tr>
<!-- END profile_fields -->


This would make the fields show up twice, which is not what we want.  We want to set up a conditional statement * to use each one separately.

Surround the top part with an if statement for the profile field we do NOT want shown (In this example it is called Money):*
Code:
<!-- IF profile.fields.LANG_NAME eq "money" -->

After the top block of code, end the if statement:
Code:
<!-- ENDIF -->


It should now look like this:

Code:
<!-- BEGIN profile_fields -->
<!-- IF profile.fields.LANG_NAME eq "money" -->
   <tr>
      <td class="row1" width="35%">
         <b class="genmed">{profile_fields.LANG_NAME}: </b>
         <!-- IF profile_fields.S_REQUIRED --><b>*</b><!-- ENDIF -->
         <!-- IF profile_fields.LANG_EXPLAIN --><br /><span class="gensmall">{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF -->
      </td>
      <td class="row2">{profile_fields.FIELD}<!-- IF profile_fields.ERROR --><br /><span class="gensmall error">{profile_fields.ERROR}</span><!-- ENDIF --></td>
   </tr>
<!-- ENDIF -->
   <tr>
      <td class="row1" width="35%">
         <b class="genmed">{profile_fields.LANG_NAME}: </b>
         <!-- IF profile_fields.S_REQUIRED --><b>*</b><!-- ENDIF -->
         <!-- IF profile_fields.LANG_EXPLAIN --><br /><span class="gensmall">{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF -->
      </td>
      <td class="row2">{profile_fields.FIELD}<!-- IF profile_fields.ERROR --><br /><span class="gensmall error">{profile_fields.ERROR}</span><!-- ENDIF --></td>
   </tr>
<!-- END profile_fields -->


Now the top part is only used for the profile field named "Money".  To make it so that this one is hidden, we need to use some good old HTML.  We need to surround the table data * with a div tag.  To make it hidden we need to add " style="display:none;" " to the tags, so they look like this:
Code:
      <td class="row1" width="35%">
         <div style="display:none;">
         <b class="genmed">{profile_fields.LANG_NAME}: </b>
         <!-- IF profile_fields.S_REQUIRED --><b>*</b><!-- ENDIF -->
         <!-- IF profile_fields.LANG_EXPLAIN --><br /><span class="gensmall">{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF -->
         </div>
      </td>
      <td class="row2">
         <div style="display:none;">{profile_fields.FIELD}<!-- IF profile_fields.ERROR --><br /><span class="gensmall error">{profile_fields.ERROR}</span><!-- ENDIF -->
         </div>
</td>



Now when the profile field's name is "Money" the profile field is hidden from view.

But the field will still show up.  The top part of the code hides the field, but the bottom part of the code still shows it.  So, to stop that we surround the bottom portion with the same IF statement, except we change the "eq" to "!=" which stands for "not equal to":
Code:
<!-- BEGIN profile_fields -->
<!-- IF profile.fields.LANG_NAME != "money" -->
   <tr>
      <td class="row1" width="35%">
         <b class="genmed">{profile_fields.LANG_NAME}: </b>
         <!-- IF profile_fields.S_REQUIRED --><b>*</b><!-- ENDIF -->
         <!-- IF profile_fields.LANG_EXPLAIN --><br /><span class="gensmall">{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF -->
      </td>
      <td class="row2">{profile_fields.FIELD}<!-- IF profile_fields.ERROR --><br /><span class="gensmall error">{profile_fields.ERROR}</span><!-- ENDIF --></td>
   </tr>
<!-- ENDIF -->


Now the bottom part of the code won't do anything when the profile field's name is "Money", so the code won't show the field at all.

The final product should look like this:
Code:
<!-- BEGIN profile_fields -->
<!-- IF profile.fields.LANG_NAME eq "money" -->
   <tr>
      <td class="row1" width="35%">
         <b class="genmed">{profile_fields.LANG_NAME}: </b>
         <!-- IF profile_fields.S_REQUIRED --><b>*</b><!-- ENDIF -->
         <!-- IF profile_fields.LANG_EXPLAIN --><br /><span class="gensmall">{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF -->
      </td>
      <td class="row2">{profile_fields.FIELD}<!-- IF profile_fields.ERROR --><br /><span class="gensmall error">{profile_fields.ERROR}</span><!-- ENDIF --></td>
   </tr>
<!-- ENDIF -->
<!-- IF profile.fields.LANG_NAME != "money" -->
   <tr>
      <td class="row1" width="35%">
         <b class="genmed">{profile_fields.LANG_NAME}: </b>
         <!-- IF profile_fields.S_REQUIRED --><b>*</b><!-- ENDIF -->
         <!-- IF profile_fields.LANG_EXPLAIN --><br /><span class="gensmall">{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF -->
      </td>
      <td class="row2">{profile_fields.FIELD}<!-- IF profile_fields.ERROR --><br /><span class="gensmall error">{profile_fields.ERROR}</span><!-- ENDIF --></td>
   </tr>
<!-- ENDIF -->
<!-- END profile_fields -->



If you want to hide multiple fields, then you will need to change the IF statements some.

For the first statement (when selecting the field), you will need to add the extra fields like this:
Code:
<!-- IF profile.fields.LANG_NAME eq "Money" || profile.fields.LANG_NAME eq "Cheese" -->
*

For the second statement (when omitting the field), you will need to add the extra fields like this:
Code:
<!-- IF profile.fields.LANG_NAME != "Money" && profile.fields.LANG_NAME != "Cheese" -->
*

You need to use || and && for the code to run correctly, for example think of it as "If the fruit is an apple OR an orange, do this.  If the fruit is not an apple AND not and orange, do that."


If there is an error in the code, you will receive a PHP error when you load the profile page, for example:
Quote:
Parse error: syntax error, unexpected...

If you receive an error like this, double check your code, specifically the "eq", "!=", "||" and "&&".



_________________


Harsh Reality - Life is a Canvas, Paint it your way!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    myfreeforum.org Forum Index -> Wiki Guides All times are GMT
Page 1 of 1
 
 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Card File  Gallery  Forum Archive
Powered by phpBB © 2001, 2005 phpBB Group
Create your own free forum | Buy a domain to use with your forum