Browse Source

Merge pull request #75 from emanuele45/required_fields

If a field is required at registration should better be into the 'requir...
emanuele45 12 years ago
parent
commit
96940f02ac
2 changed files with 27 additions and 2 deletions
  1. 4 1
      Sources/Profile.php
  2. 23 1
      Themes/default/Register.template.php

+ 4 - 1
Sources/Profile.php

@@ -697,7 +697,7 @@ function loadCustomFields($memID, $area = 'summary')
 	// Load all the relevant fields - and data.
 	$request = $smcFunc['db_query']('', '
 		SELECT
-			col_name, field_name, field_desc, field_type, field_length, field_options,
+			col_name, field_name, field_desc, field_type, show_reg, field_length, field_options,
 			default_value, bbc, enclose, placement
 		FROM {db_prefix}custom_fields
 		WHERE ' . $where,
@@ -706,6 +706,7 @@ function loadCustomFields($memID, $area = 'summary')
 		)
 	);
 	$context['custom_fields'] = array();
+	$context['custom_fields_required'] = false;
 	while ($row = $smcFunc['db_fetch_assoc']($request))
 	{
 		// Shortcut.
@@ -790,7 +791,9 @@ function loadCustomFields($memID, $area = 'summary')
 			'placement' => $row['placement'],
 			'colname' => $row['col_name'],
 			'value' => $value,
+			'show_reg' => $row['show_reg'],
 		);
+		$context['custom_fields_required'] = $context['custom_fields_required'] || $row['show_reg'];
 	}
 	$smcFunc['db_free_result']($request);
 

+ 23 - 1
Themes/default/Register.template.php

@@ -168,7 +168,26 @@ function template_registration_form()
 							<input type="text" name="openid_identifier" id="openid_url" size="30" tabindex="', $context['tabindex']++, '" value="', isset($context['openid']) ? $context['openid'] : '', '" class="input_text openid_login" />
 						</dd>
 					</dl>';
+	}
+
+	// If there is any field marked as required, show it here!
+	if (!empty($context['custom_fields_required']) && !empty($context['custom_fields']))
+	{
+		echo '
+
+					<dl class="register_form">';
 
+		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>', $field['input_html'], '</dd>';
+
+		echo '
+					</dl>';
 	}
 
 	echo '
@@ -272,12 +291,15 @@ function template_registration_form()
 	if (!empty($context['custom_fields']))
 	{
 		foreach ($context['custom_fields'] as $field)
-			echo '
+		{
+			if ($field['show_reg'] < 2)
+				echo '
 						<dt>
 							<strong', !empty($field['is_error']) ? ' style="color: red;"' : '', '>', $field['name'], ':</strong>
 							<span class="smalltext">', $field['desc'], '</span>
 						</dt>
 						<dd>', $field['input_html'], '</dd>';
+		}
 	}
 
 	// If we have either of these, close the list like a proper gent.