You are here

function profile2_form in Profile 2 7.2

Same name and namespace in other branches
  1. 7 contrib/profile2_page.inc \profile2_form()

The profile edit form.

1 string reference to 'profile2_form'
profile2_page_forms in contrib/profile2_page.module
Implements hook_forms().

File

contrib/profile2_page.inc, line 54
Adds separate pages for viewing and editing profiles.

Code

function profile2_form($form, &$form_state, $profile) {
  global $user;
  if (empty($form_state['profiles'])) {
    $form_state['profiles'][$profile->type] = $profile;
  }

  // Prevent invoking the same hooks twice, so tell profile2_attach_form() to
  // skip invoking the hooks.
  $form_state['profile2_skip_hook'] = TRUE;
  profile2_attach_form($form, $form_state);

  // If using edit title mode, add a field for the title and validate function.
  $type = profile2_get_types($profile->type);
  if (!empty($type->data['edit_label'])) {
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#description' => t('Enter a title for this profile'),
      '#required' => TRUE,
      '#default_value' => $profile->label,
      '#maxlength' => 255,
      '#weight' => -5,
    );
    $form['#validate'][] = 'profile2_form_validate';
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 40,
  );
  if (user_access('administer profiles') || $user->uid === $profile->uid && user_access("delete own {$profile->type} profile")) {
    $delete_button_label = t('Delete profile');
  }
  if (empty($profile->is_new) && !empty($delete_button_label)) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => $delete_button_label,
      '#weight' => 45,
      '#limit_validation_errors' => array(),
      '#submit' => array(
        'profile2_form_submit_delete',
      ),
    );
  }
  $form['#submit'][] = 'profile2_form_submit';
  return $form;
}