Browse Source

Merge pull request #1491 from MissAllSunday/cust_field_admin_reg

Cust field admin reg
Jessica González 10 years ago
parent
commit
96bfc2b628

+ 11 - 0
Sources/ManageRegistration.php

@@ -90,6 +90,10 @@ function AdminRegister()
 {
 	global $txt, $context, $sourcedir, $scripturl, $smcFunc;
 
+	// Are there any custom profile fields required during registration?
+	require_once($sourcedir . '/Profile.php');
+	loadCustomFields(0, 'register');
+
 	if (!empty($_POST['regSubmit']))
 	{
 		checkSession();
@@ -117,6 +121,13 @@ function AdminRegister()
 		$memberID = registerMember($regOptions);
 		if (!empty($memberID))
 		{
+			// We'll do custom fields after as then we get to use the helper function!
+			if (!empty($_POST['customfield']))
+			{
+				require_once($sourcedir . '/Profile-Modify.php');
+				makeCustomFieldChanges($memberID, 'register');
+			}
+
 			$context['new_member'] = array(
 				'id' => $memberID,
 				'name' => $_POST['user'],

+ 2 - 4
Sources/Register.php

@@ -196,7 +196,7 @@ function Register($reg_errors = array())
 		$context['username'] = $smcFunc['htmlspecialchars'](!empty($_POST['user']) ? $_POST['user'] : $_SESSION['openid']['nickname']);
 		$context['email'] = $smcFunc['htmlspecialchars'](!empty($_POST['email']) ? $_POST['email'] : $_SESSION['openid']['email']);
 	}
-	// See whether we have some prefiled values.
+	// See whether we have some pre-filled values.
 	else
 	{
 		$context += array(
@@ -206,12 +206,10 @@ function Register($reg_errors = array())
 		);
 	}
 
-	// @todo Why isn't this a simple set operation?
 	// Were there any errors?
 	$context['registration_errors'] = array();
 	if (!empty($reg_errors))
-		foreach ($reg_errors as $error)
-			$context['registration_errors'][] = $error;
+		$context['registration_errors'] = $reg_errors;
 
 	createToken('register');
 }

+ 1 - 1
Sources/Subs-Members.php

@@ -551,7 +551,7 @@ function registerMember(&$regOptions, $return_errors = false)
 
 	$smcFunc['db_free_result']($request);
 
-	// Perhaps someone else wants to check this user
+	// Perhaps someone else wants to check this user.
 	call_integration_hook('integrate_register_check', array(&$regOptions, &$reg_errors));
 
 	// If we found any errors we need to do something about it right away!

+ 12 - 5
Themes/default/Register.template.php

@@ -183,11 +183,7 @@ function template_registration_form()
 							<strong', !empty($field['is_error']) ? ' style="color: red;"' : '', '>', $field['name'], ':</strong>
 							<span class="smalltext">', $field['desc'], '</span>
 						</dt>
-						<dd>', preg_replace_callback('~<(input|select|textarea) ~', create_function('$matches', '
-							global $context;
-							return \'<\' . $matches[1] . \' tabindex="\' . $context[\'tabindex\']++ . \'"\';
-						')
-					, $field['input_html']), '</dd>';
+						<dd>', str_replace('name="', 'tabindex="' . $context['tabindex']++ .'" name="', $field['input_html']), '</dd>';
 
 		echo '
 					</dl>';
@@ -562,6 +558,17 @@ function template_admin_register()
 						</dd>';
 	}
 
+	// If there is any field marked as required, show it here!
+	if (!empty($context['custom_fields_required']) && !empty($context['custom_fields']))
+		foreach ($context['custom_fields'] as $field)
+			if ($field['show_reg'] > 1)
+				echo '
+						<dt>
+							<strong', !empty($field['is_error']) ? ' style="color: red;"' : '', '>', $field['name'], ':</strong>
+							<span class="smalltext">', $field['desc'], '</span>
+						</dt>
+						<dd>', str_replace('name="', 'tabindex="' . $context['tabindex']++ .'" name="', $field['input_html']), '</dd>';
+
 	echo '
 						<dt>
 							<strong><label for="emailPassword_check">', $txt['admin_register_email_detail'], ':</label></strong>