summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2004-09-19 13:28:11 +0000
committerDries Buytaert <dries@buytaert.net>2004-09-19 13:28:11 +0000
commit6dbd0bcfb4c79853ca1402d9f85a325853b01411 (patch)
tree6cc1058b101a67015b722e0affb29a21b5d729d6 /modules
parent0ca171f2a9e802c150b30390bad218208458d33a (diff)
downloadbrdo-6dbd0bcfb4c79853ca1402d9f85a325853b01411.tar.gz
brdo-6dbd0bcfb4c79853ca1402d9f85a325853b01411.tar.bz2
- Patch #6500 by Mathias with help from Steven: made it possible to add fields to the registration form. This feature used to exist.
Diffstat (limited to 'modules')
-rw-r--r--modules/profile.module52
-rw-r--r--modules/profile/profile.module52
-rw-r--r--modules/user.module20
-rw-r--r--modules/user/user.module20
4 files changed, 106 insertions, 38 deletions
diff --git a/modules/profile.module b/modules/profile.module
index 2aef8aa03..c31c21c57 100644
--- a/modules/profile.module
+++ b/modules/profile.module
@@ -150,7 +150,12 @@ function profile_load_profile(&$user) {
}
function profile_save_profile(&$edit, &$user, $category) {
- $result = db_query("SELECT fid, name, type FROM {profile_fields} WHERE LOWER(category) = '%s'", strtolower($category));
+ if (($_GET['q'] == 'user/register') ? 1 : 0) {
+ $result = db_query('SELECT fid, name, type FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
+ }
+ else {
+ $result = db_query("SELECT fid, name, type FROM {profile_fields} WHERE LOWER(category) = '%s'", strtolower($category));
+ }
while ($field = db_fetch_object($result)) {
if (_profile_field_serialize($field->type)) {
$edit[$field->name] = serialize($edit[$field->name]);
@@ -240,22 +245,29 @@ function _profile_form_explanation($field) {
function profile_form_profile($edit, $user, $category) {
- $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = '%s' ORDER BY weight", strtolower($category));
+ if (($_GET['q'] == 'user/register') ? 1 : 0) {
+ $result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
+ }
+ else {
+ $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = '%s' ORDER BY weight", strtolower($category));
+ }
+ $fields = array();
while ($field = db_fetch_object($result)) {
+ $category = $field->category;
switch ($field->type) {
case 'textfield':
case 'url':
- $output .= form_textfield($field->title, $field->name, $edit[$field->name], 70, 255, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_textfield($field->title, $field->name, $edit[$field->name], 70, 255, _profile_form_explanation($field), NULL, $field->required);
break;
case 'textarea':
- $output .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
break;
case 'list':
- $output .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
break;
case 'checkbox':
- $output .= form_checkbox($field->title, $field->name, 1, $edit[$field->name], _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_checkbox($field->title, $field->name, 1, $edit[$field->name], _profile_form_explanation($field), NULL, $field->required);
break;
case 'selection':
$options = array('--');
@@ -266,16 +278,19 @@ function profile_form_profile($edit, $user, $category) {
}
}
- $output .= form_select($field->title, $field->name, $edit[$field->name], $options, _profile_form_explanation($field), 0, 0, $field->required);
+ $fields[$category] .= form_select($field->title, $field->name, $edit[$field->name], $options, _profile_form_explanation($field), 0, 0, $field->required);
break;
case 'date':
- $output .= _profile_date_field($field, $edit);
+ $fields[$category] .= _profile_date_field($field, $edit);
break;
}
}
- if ($output) {
- return array(array('title' => $category, 'data' => $output));
+ if ($fields) {
+ foreach ($fields as $category => $data) {
+ $output[] = array('title' => $category, 'data' => $data);
+ }
+ return $output;
}
}
@@ -328,7 +343,13 @@ function _profile_map_month($month) {
}
function profile_validate_profile($edit, $category) {
- $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = '%s' ORDER BY weight", strtolower($category));
+
+ if (($_GET['q'] == 'user/register') ? 1 : 0) {
+ $result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
+ }
+ else {
+ $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = '%s' ORDER BY weight", strtolower($category));
+ }
while ($field = db_fetch_object($result)) {
if ($edit[$field->name]) {
@@ -361,6 +382,8 @@ function profile_user($type, &$edit, &$user, $category = NULL) {
switch ($type) {
case 'load':
return profile_load_profile($user);
+ case 'register':
+ return profile_form_profile($edit, $user, $category);
case 'update':
case 'insert':
return profile_save_profile($edit, $user, $category);
@@ -418,7 +441,7 @@ function profile_admin_add($type) {
}
if (!form_get_errors()) {
- db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, visibility, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s')", $data['title'], $data['name'], $data['explanation'], $data['category'], $type, $data['weight'], $data['required'], $data['visibility'], $data['options'], $data['page']);
+ db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s')", $data['title'], $data['name'], $data['explanation'], $data['category'], $type, $data['weight'], $data['required'], $data['register'], $data['visibility'], $data['options'], $data['page']);
drupal_set_message(t('The field has been created.'));
drupal_goto('admin/user/configure/profile');
@@ -443,7 +466,7 @@ function profile_admin_edit($fid) {
profile_validate_form($data);
if (!form_get_errors()) {
- db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, visibility = %d, options = '%s', page = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['required'], $data['visibility'], $data['options'], $data['page'], $fid);
+ db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, options = '%s', page = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['required'], $data['register'], $data['visibility'], $data['options'], $data['page'], $fid);
drupal_set_message(t('The field has been updated.'));
drupal_goto('admin/user/configure/profile');
@@ -483,7 +506,8 @@ Unless you know what you are doing, it is highly recommended that you prefix the
else {
$group .= form_textfield(t('Page title'), 'page', $edit['page'], 70, 128, t('The title of the page showing all users with the specified field. Only applicable if the field is configured to be shown on member listings.'));
}
- $group .= form_checkbox(t('Required field.'), 'required', 1, $edit['required']);
+ $group .= form_checkbox(t('The user must enter a value.'), 'required', 1, $edit['required']);
+ $group .= form_checkbox(t('Visible in user registration form.'), 'register', 1, $edit['register']);
$output = form_group(t('Field settings'), $group);
$output .= form_submit(t('Save field'));
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index 2aef8aa03..c31c21c57 100644
--- a/modules/profile/profile.module
+++ b/modules/profile/profile.module
@@ -150,7 +150,12 @@ function profile_load_profile(&$user) {
}
function profile_save_profile(&$edit, &$user, $category) {
- $result = db_query("SELECT fid, name, type FROM {profile_fields} WHERE LOWER(category) = '%s'", strtolower($category));
+ if (($_GET['q'] == 'user/register') ? 1 : 0) {
+ $result = db_query('SELECT fid, name, type FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
+ }
+ else {
+ $result = db_query("SELECT fid, name, type FROM {profile_fields} WHERE LOWER(category) = '%s'", strtolower($category));
+ }
while ($field = db_fetch_object($result)) {
if (_profile_field_serialize($field->type)) {
$edit[$field->name] = serialize($edit[$field->name]);
@@ -240,22 +245,29 @@ function _profile_form_explanation($field) {
function profile_form_profile($edit, $user, $category) {
- $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = '%s' ORDER BY weight", strtolower($category));
+ if (($_GET['q'] == 'user/register') ? 1 : 0) {
+ $result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
+ }
+ else {
+ $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = '%s' ORDER BY weight", strtolower($category));
+ }
+ $fields = array();
while ($field = db_fetch_object($result)) {
+ $category = $field->category;
switch ($field->type) {
case 'textfield':
case 'url':
- $output .= form_textfield($field->title, $field->name, $edit[$field->name], 70, 255, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_textfield($field->title, $field->name, $edit[$field->name], 70, 255, _profile_form_explanation($field), NULL, $field->required);
break;
case 'textarea':
- $output .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
break;
case 'list':
- $output .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_textarea($field->title, $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
break;
case 'checkbox':
- $output .= form_checkbox($field->title, $field->name, 1, $edit[$field->name], _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category] .= form_checkbox($field->title, $field->name, 1, $edit[$field->name], _profile_form_explanation($field), NULL, $field->required);
break;
case 'selection':
$options = array('--');
@@ -266,16 +278,19 @@ function profile_form_profile($edit, $user, $category) {
}
}
- $output .= form_select($field->title, $field->name, $edit[$field->name], $options, _profile_form_explanation($field), 0, 0, $field->required);
+ $fields[$category] .= form_select($field->title, $field->name, $edit[$field->name], $options, _profile_form_explanation($field), 0, 0, $field->required);
break;
case 'date':
- $output .= _profile_date_field($field, $edit);
+ $fields[$category] .= _profile_date_field($field, $edit);
break;
}
}
- if ($output) {
- return array(array('title' => $category, 'data' => $output));
+ if ($fields) {
+ foreach ($fields as $category => $data) {
+ $output[] = array('title' => $category, 'data' => $data);
+ }
+ return $output;
}
}
@@ -328,7 +343,13 @@ function _profile_map_month($month) {
}
function profile_validate_profile($edit, $category) {
- $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = '%s' ORDER BY weight", strtolower($category));
+
+ if (($_GET['q'] == 'user/register') ? 1 : 0) {
+ $result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
+ }
+ else {
+ $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = '%s' ORDER BY weight", strtolower($category));
+ }
while ($field = db_fetch_object($result)) {
if ($edit[$field->name]) {
@@ -361,6 +382,8 @@ function profile_user($type, &$edit, &$user, $category = NULL) {
switch ($type) {
case 'load':
return profile_load_profile($user);
+ case 'register':
+ return profile_form_profile($edit, $user, $category);
case 'update':
case 'insert':
return profile_save_profile($edit, $user, $category);
@@ -418,7 +441,7 @@ function profile_admin_add($type) {
}
if (!form_get_errors()) {
- db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, visibility, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s')", $data['title'], $data['name'], $data['explanation'], $data['category'], $type, $data['weight'], $data['required'], $data['visibility'], $data['options'], $data['page']);
+ db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s')", $data['title'], $data['name'], $data['explanation'], $data['category'], $type, $data['weight'], $data['required'], $data['register'], $data['visibility'], $data['options'], $data['page']);
drupal_set_message(t('The field has been created.'));
drupal_goto('admin/user/configure/profile');
@@ -443,7 +466,7 @@ function profile_admin_edit($fid) {
profile_validate_form($data);
if (!form_get_errors()) {
- db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, visibility = %d, options = '%s', page = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['required'], $data['visibility'], $data['options'], $data['page'], $fid);
+ db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, options = '%s', page = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['required'], $data['register'], $data['visibility'], $data['options'], $data['page'], $fid);
drupal_set_message(t('The field has been updated.'));
drupal_goto('admin/user/configure/profile');
@@ -483,7 +506,8 @@ Unless you know what you are doing, it is highly recommended that you prefix the
else {
$group .= form_textfield(t('Page title'), 'page', $edit['page'], 70, 128, t('The title of the page showing all users with the specified field. Only applicable if the field is configured to be shown on member listings.'));
}
- $group .= form_checkbox(t('Required field.'), 'required', 1, $edit['required']);
+ $group .= form_checkbox(t('The user must enter a value.'), 'required', 1, $edit['required']);
+ $group .= form_checkbox(t('Visible in user registration form.'), 'register', 1, $edit['register']);
$output = form_group(t('Field settings'), $group);
$output .= form_submit(t('Save field'));
diff --git a/modules/user.module b/modules/user.module
index c2727801f..161d36073 100644
--- a/modules/user.module
+++ b/modules/user.module
@@ -925,7 +925,7 @@ function user_register($edit = array()) {
// TODO: Is this necessary? Won't session_write() replicate this?
unset($edit['session']);
- $account = user_save('', array('name' => $edit['name'], 'pass' => $pass, 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => array(_user_authenticated_id()), 'status' => (variable_get('user_register', 1) == 1 ? 1 : 0)));
+ $account = user_save('', array_merge(array('name' => $edit['name'], 'pass' => $pass, 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => array(_user_authenticated_id()), 'status' => (variable_get('user_register', 1) == 1 ? 1 : 0)), $edit));
watchdog('user', t('New user: %name %e-mail.', array('%name' => '<em>'. $edit['name'] .'</em>', '%e-mail' => '<em>&lt;'. $edit['mail'] .'&gt;</em>')), l(t('edit'), 'user/'. $account->uid .'/edit'));
$variables = array('%username' => $edit['name'], '%site' => variable_get('site_name', 'drupal'), '%password' => $pass, '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $edit['mail'], '%date' => format_date(time()), '%login_uri' => url('user', NULL, NULL, TRUE), '%edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE));
@@ -969,8 +969,18 @@ function user_register($edit = array()) {
$affiliates = implode(', ', $affiliates);
$output .= '<p>'. t('Note: if you have an account with one of our affiliates (%s), you may <a href="%login_uri">login now</a> instead of registering.', array('%s' => $affiliates, '%login_uri' => url('user'))) .'</p>';
}
- $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'));
- $output .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64, t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.'));
+ $default = form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'));
+ $default .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64, t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.'));
+ $extra = _user_forms($edit, $account, $category, 'register');
+ // Only display form_group around default fields if there are other groups.
+ if ($extra) {
+ $output .= form_group(t('Account information'), $default);
+ $output .= $extra;
+ }
+ else {
+ $output .= $default;
+ }
+
$output .= form_submit(t('Create new account'));
return form($output);
@@ -1654,10 +1664,10 @@ function _user_sort($a, $b) {
/**
* Retrieve a list of all form elements for the specified category.
*/
-function _user_forms(&$edit, $account, $category) {
+function _user_forms(&$edit, $account, $category, $hook = 'form') {
$groups = array();
foreach (module_list() as $module) {
- if ($data = module_invoke($module, 'user', 'form', $edit, $account, $category)) {
+ if ($data = module_invoke($module, 'user', $hook, $edit, $account, $category)) {
$groups = array_merge($data, $groups);
}
}
diff --git a/modules/user/user.module b/modules/user/user.module
index c2727801f..161d36073 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -925,7 +925,7 @@ function user_register($edit = array()) {
// TODO: Is this necessary? Won't session_write() replicate this?
unset($edit['session']);
- $account = user_save('', array('name' => $edit['name'], 'pass' => $pass, 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => array(_user_authenticated_id()), 'status' => (variable_get('user_register', 1) == 1 ? 1 : 0)));
+ $account = user_save('', array_merge(array('name' => $edit['name'], 'pass' => $pass, 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => array(_user_authenticated_id()), 'status' => (variable_get('user_register', 1) == 1 ? 1 : 0)), $edit));
watchdog('user', t('New user: %name %e-mail.', array('%name' => '<em>'. $edit['name'] .'</em>', '%e-mail' => '<em>&lt;'. $edit['mail'] .'&gt;</em>')), l(t('edit'), 'user/'. $account->uid .'/edit'));
$variables = array('%username' => $edit['name'], '%site' => variable_get('site_name', 'drupal'), '%password' => $pass, '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $edit['mail'], '%date' => format_date(time()), '%login_uri' => url('user', NULL, NULL, TRUE), '%edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE));
@@ -969,8 +969,18 @@ function user_register($edit = array()) {
$affiliates = implode(', ', $affiliates);
$output .= '<p>'. t('Note: if you have an account with one of our affiliates (%s), you may <a href="%login_uri">login now</a> instead of registering.', array('%s' => $affiliates, '%login_uri' => url('user'))) .'</p>';
}
- $output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'));
- $output .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64, t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.'));
+ $default = form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'));
+ $default .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64, t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.'));
+ $extra = _user_forms($edit, $account, $category, 'register');
+ // Only display form_group around default fields if there are other groups.
+ if ($extra) {
+ $output .= form_group(t('Account information'), $default);
+ $output .= $extra;
+ }
+ else {
+ $output .= $default;
+ }
+
$output .= form_submit(t('Create new account'));
return form($output);
@@ -1654,10 +1664,10 @@ function _user_sort($a, $b) {
/**
* Retrieve a list of all form elements for the specified category.
*/
-function _user_forms(&$edit, $account, $category) {
+function _user_forms(&$edit, $account, $category, $hook = 'form') {
$groups = array();
foreach (module_list() as $module) {
- if ($data = module_invoke($module, 'user', 'form', $edit, $account, $category)) {
+ if ($data = module_invoke($module, 'user', $hook, $edit, $account, $category)) {
$groups = array_merge($data, $groups);
}
}