diff options
author | Dries Buytaert <dries@buytaert.net> | 2004-03-27 14:50:56 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2004-03-27 14:50:56 +0000 |
commit | 5f17ad3c2df10663638683917ee92e366f79140c (patch) | |
tree | 0e4a455dcf0a9afed450ff0638e0641c32a6dac9 | |
parent | 3fbfc5203041b822b7bced5618fd310ba784cf5e (diff) | |
download | brdo-5f17ad3c2df10663638683917ee92e366f79140c.tar.gz brdo-5f17ad3c2df10663638683917ee92e366f79140c.tar.bz2 |
- Profile module improvement:
* Made it possible to set certain fields as 'required'.
To do:
* Mark them as required visually.
* Add required fields to the subscription page.
-rw-r--r-- | database/database.mysql | 1 | ||||
-rw-r--r-- | database/updates.inc | 8 | ||||
-rw-r--r-- | modules/profile.module | 8 | ||||
-rw-r--r-- | modules/profile/profile.module | 8 | ||||
-rw-r--r-- | modules/user.module | 30 | ||||
-rw-r--r-- | modules/user/user.module | 30 |
6 files changed, 54 insertions, 31 deletions
diff --git a/database/database.mysql b/database/database.mysql index 874bde898..fd7f22980 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 663bccf61..f5ddfc7fb 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 d382687dc..e3db77656 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 d382687dc..e3db77656 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 13cb6c7a6..01ba43601 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 @@ -1540,6 +1527,23 @@ function user_admin_edit($edit = array()) { } /* + ** 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 13cb6c7a6..01ba43601 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 @@ -1540,6 +1527,23 @@ function user_admin_edit($edit = array()) { } /* + ** 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. */ |