diff --git a/database/database.mysql b/database/database.mysql index 874bde898b0..fd7f2298010 100644 --- a/database/database.mysql +++ b/database/database.mysql @@ -325,6 +325,7 @@ CREATE TABLE profile_fields ( page varchar(255) default NULL, type varchar(128) default NULL, weight tinyint(1) DEFAULT '0' NOT NULL, + required tinyint(1) DEFAULT '0' NOT NULL, overview tinyint(1) DEFAULT '0' NOT NULL, options text, KEY category (category), diff --git a/database/updates.inc b/database/updates.inc index 663bccf612a..f5ddfc7fba5 100644 --- a/database/updates.inc +++ b/database/updates.inc @@ -52,7 +52,8 @@ $sql_updates = array( "2004-02-03" => "update_78", "2004-02-21" => "update_79", "2004-03-11: first update since Drupal 4.4.0 release" => "update_80", - "2004-02-20" => "update_81" + "2004-02-20" => "update_81", + "2004-02-27" => "update_82" ); function update_32() { @@ -890,6 +891,11 @@ function update_81() { return $ret; } +function update_82() { + $ret[] = update_sql("ALTER TABLE {profile_fields} ADD required tinyint(1) DEFAULT '0' NOT NULL"); + return $ret; +} + function update_sql($sql) { $edit = $_POST["edit"]; $result = db_query($sql); diff --git a/modules/profile.module b/modules/profile.module index d382687dcb9..e3db77656b6 100644 --- a/modules/profile.module +++ b/modules/profile.module @@ -185,6 +185,9 @@ function profile_validate_profile($edit) { return t("The value provided for '%field' is not a valid URL.", array('%field' => $field->title)); } } + else if ($field->required) { + return t("The field '%field' is required.", array('%field' => $field->title)); + } } return $edit; @@ -240,7 +243,7 @@ function profile_admin_add($type) { drupal_set_message($error, 'error'); } else { - db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, overview, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s')", $data['title'], $data['name'], $data['explanation'], $data['category'], $type, $data['weight'], $data['overview'], $data['options'], $data['page']); + db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, overview, 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['overview'], $data['options'], $data['page']); drupal_set_message(t('the field has been created.')); } @@ -262,7 +265,7 @@ function profile_admin_edit($fid) { } else { - db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, overview = %d, options = '%s', page = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['overview'], $data['options'], $data['page'], $fid); + db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, overview = %d, options = '%s', page = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['required'], $data['overview'], $data['options'], $data['page'], $fid); drupal_set_message(t('the field has been updated.')); } @@ -291,6 +294,7 @@ Unless you know what you are doing, it is highly recommended that you prefix the $group .= form_textarea(t('Selection options'), 'options', $edit['options'], 70, 8, t("A list of all options. Put each option on a separate line. Example options are 'red', 'blue', 'green', etc.")); } $group .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t("The weights define the order in which the form fields are shown. Lighter fields \"float up\" towards the top of the category.")); + $group .= form_checkbox(t('Required field.'), 'required', 1, $edit['required']); $output = form_group(t('Field settings'), $group); $group = ''; diff --git a/modules/profile/profile.module b/modules/profile/profile.module index d382687dcb9..e3db77656b6 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -185,6 +185,9 @@ function profile_validate_profile($edit) { return t("The value provided for '%field' is not a valid URL.", array('%field' => $field->title)); } } + else if ($field->required) { + return t("The field '%field' is required.", array('%field' => $field->title)); + } } return $edit; @@ -240,7 +243,7 @@ function profile_admin_add($type) { drupal_set_message($error, 'error'); } else { - db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, overview, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s')", $data['title'], $data['name'], $data['explanation'], $data['category'], $type, $data['weight'], $data['overview'], $data['options'], $data['page']); + db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, overview, 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['overview'], $data['options'], $data['page']); drupal_set_message(t('the field has been created.')); } @@ -262,7 +265,7 @@ function profile_admin_edit($fid) { } else { - db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, overview = %d, options = '%s', page = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['overview'], $data['options'], $data['page'], $fid); + db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, overview = %d, options = '%s', page = '%s' WHERE fid = %d", $data['title'], $data['name'], $data['explanation'], $data['category'], $data['weight'], $data['required'], $data['overview'], $data['options'], $data['page'], $fid); drupal_set_message(t('the field has been updated.')); } @@ -291,6 +294,7 @@ Unless you know what you are doing, it is highly recommended that you prefix the $group .= form_textarea(t('Selection options'), 'options', $edit['options'], 70, 8, t("A list of all options. Put each option on a separate line. Example options are 'red', 'blue', 'green', etc.")); } $group .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t("The weights define the order in which the form fields are shown. Lighter fields \"float up\" towards the top of the category.")); + $group .= form_checkbox(t('Required field.'), 'required', 1, $edit['required']); $output = form_group(t('Field settings'), $group); $group = ''; diff --git a/modules/user.module b/modules/user.module index 13cb6c7a62f..01ba436019b 100644 --- a/modules/user.module +++ b/modules/user.module @@ -1512,19 +1512,6 @@ function user_admin_edit($edit = array()) { if ($account = user_load(array('uid' => $id))) { if ($op == t("Save account")) { - foreach (module_list() as $module) { - if (module_hook($module, 'user')) { - $result = module_invoke($module, 'user', 'validate', $edit, $account); - } - if (is_array($result)) { - $data = array_merge($data, $result); - } - elseif (is_string($result)) { - $error = $result; - break; - } - } - // TODO: this display/edit/validate should be moved to a new profile module implementing the _user hooks if ($error = user_validate_name($edit['name'])) { // do nothing @@ -1539,6 +1526,23 @@ function user_admin_edit($edit = array()) { $error = t("The e-mail address '%s' is already taken.", array("%s" => $edit['mail'])); } + /* + ** Validate fields added by other modules. + */ + + foreach (module_list() as $module) { + if (module_hook($module, 'user')) { + $result = module_invoke($module, 'user', 'validate', $edit, $account); + } + if (is_array($result)) { + $data = array_merge($data, $result); + } + elseif (is_string($result)) { + $error = $result; + break; + } + } + /* ** If required, validate the picture. */ diff --git a/modules/user/user.module b/modules/user/user.module index 13cb6c7a62f..01ba436019b 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1512,19 +1512,6 @@ function user_admin_edit($edit = array()) { if ($account = user_load(array('uid' => $id))) { if ($op == t("Save account")) { - foreach (module_list() as $module) { - if (module_hook($module, 'user')) { - $result = module_invoke($module, 'user', 'validate', $edit, $account); - } - if (is_array($result)) { - $data = array_merge($data, $result); - } - elseif (is_string($result)) { - $error = $result; - break; - } - } - // TODO: this display/edit/validate should be moved to a new profile module implementing the _user hooks if ($error = user_validate_name($edit['name'])) { // do nothing @@ -1539,6 +1526,23 @@ function user_admin_edit($edit = array()) { $error = t("The e-mail address '%s' is already taken.", array("%s" => $edit['mail'])); } + /* + ** Validate fields added by other modules. + */ + + foreach (module_list() as $module) { + if (module_hook($module, 'user')) { + $result = module_invoke($module, 'user', 'validate', $edit, $account); + } + if (is_array($result)) { + $data = array_merge($data, $result); + } + elseif (is_string($result)) { + $error = $result; + break; + } + } + /* ** If required, validate the picture. */