function profile_field_form_validate in Drupal 5
Same name and namespace in other branches
- 4 modules/profile.module \profile_field_form_validate()
- 6 modules/profile/profile.admin.inc \profile_field_form_validate()
- 7 modules/profile/profile.admin.inc \profile_field_form_validate()
Validate profile_field_form submissions.
File
- modules/
profile/ profile.module, line 307 - Support for configurable user profiles.
Code
function profile_field_form_validate($form_id, $form_values) {
// Validate the 'field name':
if (preg_match('/[^a-zA-Z0-9_-]/', $form_values['name'])) {
form_set_error('name', t('The specified form name contains one or more illegal characters. Spaces or any other special characters except dash (-) and underscore (_) are not allowed.'));
}
if (in_array($form_values['name'], user_fields())) {
form_set_error('name', t('The specified form name is reserved for use by Drupal.'));
}
// Validate the category:
if (!$form_values['category']) {
form_set_error('category', t('You must enter a category.'));
}
if ($form_values['category'] == 'account') {
form_set_error('category', t('The specified category name is reserved for use by Drupal.'));
}
$args1 = array(
$form_values['title'],
$form_values['category'],
);
$args2 = array(
$form_values['name'],
);
$query_suffix = '';
if (isset($form_values['fid'])) {
$args1[] = $args2[] = $form_values['fid'];
$query_suffix = ' AND fid != %d';
}
if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE title = '%s' AND category = '%s'" . $query_suffix, $args1))) {
form_set_error('title', t('The specified title is already in use.'));
}
if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'" . $query_suffix, $args2))) {
form_set_error('name', t('The specified name is already in use.'));
}
if ($form_values['visibility'] == PROFILE_HIDDEN) {
if ($form_values['required']) {
form_set_error('required', t('A hidden field cannot be required.'));
}
if ($form_values['register']) {
form_set_error('register', t('A hidden field cannot be set to visible on the user registration form.'));
}
}
}