phpBBHacks.com - Making a Profile Field Required
Find affordable web hosting packages at iFroggy Hosting
StatsForums Home   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in
FAQFAQ   SearchSearch   MemberlistMemberlist   TutorialsTutorials   ContactContact Us
Username:    Password:
Remember Me?    
   I Lost My Password!
Bookmark and Share
Post new topic   Reply to topic    phpBBHacks.com Support Forums Forum Index -> phpBB 2: Customizing Your phpBB
 See a User Guidelines violation? Please contact us.
Author Message

Thoul
VIP

Joined: 30 Jul 2002
Posts: 18040
Location: USA

PostPosted: December 3rd 2003, 3:08 pm    Post subject: Making a Profile Field Required Reply with quote

In customizing your forum's registration, you may want to make certain profile fields required. This is a short guide to doing so. In this guide, we'll make the Location field required. You can do this with any field, however. Just use the name of your field, such as "user_instrument," instead of "location" in the code changes below.

The are two types of required fields: ones required at registration only, and ones required in both registration and profile editing. To require a field at registration only, make this change to usercp_register.php.

Code:
#
#-----[ FIND ]------------------------------------------
#

      if ( empty($username) || empty($new_password) || empty($password_confirm) || empty($email) )


#
#-----[ IN-LINE FIND ]------------------------------------------
#

empty($email)


 #
 #-----[ IN-LINE AFTER, ADD ]------------------------------------------
 #
 
  || empty($location)


If you want to require a profile field during both registration and profile editing, make these changes to usercp_register.php instead.
Code:
#
#-----[ FIND ]------------------------------------------
#
   include($phpbb_root_path . 'includes/usercp_avatar.'.$phpEx);

   $passwd_sql = '';

#
#-----[ BEFORE, ADD ]------------------------------------------
#

   if( empty($location) )
   {
      $error = TRUE;
      $error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . $lang['Fields_empty'];
   }


Last edited by Thoul on July 22nd 2005, 9:00 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website

Thoul
VIP

Joined: 30 Jul 2002
Posts: 18040
Location: USA

PostPosted: July 22nd 2005, 8:58 am    Post subject: Reply with quote

It is also a good idea to indicate that the field is now required in the registration and/or profile editing forms. You will need to edit the profile_add_body.tpl for each template installed on your forum. This tutorial will use code from the subSilver file for examples, but please be aware that the relevant code will be different on some other templates.

The first step is to find the area of the file that needs to be edited. Search for the name of the profile field you are requiring in the file. You should be able to find it in code similar to the next block, which is for the "location" field.
Code:
   <tr>
     <td class="row1"><span class="gen">{L_LOCATION}:</span></td>
     <td class="row2">
      <input type="text" class="post"style="width: 200px"  name="location" size="25" maxlength="100" value="{LOCATION}" />
     </td>
   </tr>


Now you need to find the line within this code that contains the name of the field, as displayed on the registration/profile pages. The name is usually represented by {L_SOMETHING}, like {L_LOCATION}. Look for a colon (:) - this will follow the name in most cases.

If you are only requiring the field during registration, you need to add the following code after the name and colon. Please note that the first and last lines of this new code must be on lines separate from all other code in this file.
Code:
<!-- BEGIN switch_user_logged_out -->
 *
<!-- END switch_user_logged_out -->


Here is an example of the fully edited location field, when required at registration only.
Code:
   <tr>
     <td class="row1"><span class="gen">{L_LOCATION}:
<!-- BEGIN switch_user_logged_out -->
 *
<!-- END switch_user_logged_out -->
</span></td>
     <td class="row2">
      <input type="text" class="post"style="width: 200px"  name="location" size="25" maxlength="100" value="{LOCATION}" />
     </td>
   </tr>


When requiring the field during both registration and profile editing, the BEGIN and END lines are not needed. You can simply add the " *" after the name and colon. Let's look at an example of this.
Code:
   <tr>
     <td class="row1"><span class="gen">{L_LOCATION}: *</span></td>
     <td class="row2">
      <input type="text" class="post"style="width: 200px"  name="location" size="25" maxlength="100" value="{LOCATION}" />
     </td>
   </tr>

_________________
Fringes of Algo - Phantasy Star Community
TV Blitz Forums - Television Discussion Community
phpBB Smith: Modifications

70+ Listings @ phpBBHacks.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    phpBBHacks.com Support Forums Forum Index -> phpBB 2: Customizing Your phpBB All times are GMT - 6 Hours
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



Links: Big Message Boards - Free JavaScript - phpBB2 - phpbb styles - Suporte phpBB - phpBB Česky - phpBB Turkiye - phpBBArabia.com - phpBB-fr.com - Romanian phpBB online community - phpBB-TW.net - phpBBservice.nl - phpBB Brasil - phpBB Portugal - phpBBpersian.com

Network: iFroggy Hosting - PhotoshopForums.com - Managing Online Forums - ManagingCommunities.com - CommunityAdmins.com - KarateForums.com - Bad Boy Blog - SodaRatings.com - Patrick O'Keefe

< Advertising - Contact Us - Disclosure Policy - Staff - User Guidelines >

Copyright © 2001-2012. iFroggy Network, phpBBHacks.com. All Rights Reserved. Privacy Policy. We Support phpBBHacks.com (of course!).
Powered by phpBB © phpBB Group. phpBB SEO. We are in no way affiliated with the phpBB Group. phpBB is copyright to the phpBB Group.