Archive for myfreeforum.org Before posting please check the "stickies" in the support forums.
Please ask questions in real English and not "txt". You will get a better response.
Please do not ask support questions via PMs.
 


       myfreeforum.org Forum Index -> Wiki Guides
Zudane

Hiding profile fields in UCP in phpbb3

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 "&&".

       myfreeforum.org Forum Index -> Wiki Guides
Page 1 of 1
Create your own free forum | Buy a domain to use with your forum