phpBBHacks.com, the place for phpBB users

Bookmark and Share

Making a Profile Field Required

Making a Profile Field Required

Postby Thoul » December 3rd 2003, 4:08 pm

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: Select all
#
#-----[ 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: Select all
#
#-----[ 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, 10:00 am, edited 1 time in total.
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Postby Thoul » July 22nd 2005, 9:58 am

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: Select all
	<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: Select all
<!-- 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: Select all
	<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: Select all
	<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>
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA


Return to phpBB 2: Customizing Your phpBB

Who is online

Users browsing this forum: No registered users and 0 guests