profile_admin_add

Versions
4.6
profile_admin_add($type)

Menu callback; adds a new field to all user profiles.

Code

modules/profile.module, line 437

<?php
function profile_admin_add($type) {
  if ($_POST['op']) {
    $data = $_POST['edit'];

    // Validate the form:
    profile_validate_form($data);

    if (db_result(db_query("SELECT fid FROM {profile_fields} WHERE title = '%s' AND category = '%s'", $data['title'], $data['category']))) {
      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'", $data['name']))) {
      form_set_error('name', t('The specified name is already in use.'));
    }

    if (!form_get_errors()) {
      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']);

      cache_clear_all();

      drupal_set_message(t('The field has been created.'));
      drupal_goto('admin/settings/profile');
    }
  }
  else {
    $data = array('name' => 'profile_');
  }

  drupal_set_title(t('Add new %type', array('%type' => _profile_field_types($type))));
  print theme('page', _profile_field_form($type, $data));
}
?>
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.