profile_field_form_validate

Versions
4.7 – 5
profile_field_form_validate($form_id, $form_values)
6 – 7
profile_field_form_validate($form, &$form_state)

Validate profile_field_form submissions.

Code

modules/profile/profile.module, line 307

<?php
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.'));
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.