You are here

function redhen_contact_contact_form_submit in RedHen CRM 7

Submit callback for redhen_contact_contact_form().

1 string reference to 'redhen_contact_contact_form_submit'
redhen_contact_contact_form in modules/redhen_contact/includes/redhen_contact.forms.inc
Form callback: create or edit a contact.

File

modules/redhen_contact/includes/redhen_contact.forms.inc, line 121
Forms for creating, editing, and deleting contacts.

Code

function redhen_contact_contact_form_submit($form, &$form_state) {
  $contact =& $form_state['redhen_contact'];

  // Set the contact's author uid.
  global $user;
  $contact->author_uid = $user->uid;

  // Save default parameters back into the $contact object.
  $contact->first_name = $form_state['values']['first_name'];
  $contact->middle_name = $form_state['values']['middle_name'];
  $contact->last_name = $form_state['values']['last_name'];

  // Notify field widgets.
  field_attach_submit('redhen_contact', $contact, $form, $form_state);

  // Save the contact.
  $contact = redhen_contact_save($contact);
  $wrapper = entity_metadata_wrapper('redhen_contact', $contact);
  if ($form_state['build_info']['form_id'] == 'redhen_contact_user_contact_form') {
    drupal_set_message(t('Contact information saved.'));
    $form_state['redirect'] = $wrapper->user->url
      ->value();
  }
  else {

    // Only show a message if creating a contact using RedHen's forms.
    $menu_item = menu_get_item();
    if (strpos($menu_item['path'], 'redhen/contact') === 0) {
      drupal_set_message(t('Contact %name saved.', array(
        '%name' => $wrapper->full_name
          ->value(),
      )));
    }
    if ($form_state['build_info']['form_id'] == 'redhen_contact_contact_form') {
      $form_state['redirect'] = $wrapper->url
        ->value();
    }
  }
}