function redhen_contact_contact_form in RedHen CRM 7
Form callback: create or edit a contact.
Parameters
$contact: The contact object to edit or for a create form an empty contact object with only a contact type defined.
2 calls to redhen_contact_contact_form()
- redhen_contact_user_contact_form in modules/
redhen_contact/ includes/ redhen_contact.forms.inc - A version of the RedHen Contact form displayed as a tab on Users.
- _redhen_contact_user_embed_contact_form in modules/
redhen_contact/ redhen_contact.module - Helper function to embed a contact form on a user form.
4 string references to 'redhen_contact_contact_form'
- redhen_contact_add_page in modules/
redhen_contact/ includes/ redhen_contact.pages.inc - Page callback for adding a contact.
- redhen_contact_contact_form_submit in modules/
redhen_contact/ includes/ redhen_contact.forms.inc - Submit callback for redhen_contact_contact_form().
- redhen_contact_menu in modules/
redhen_contact/ redhen_contact.module - Implements hook_menu().
- redhen_relation_connection_form in modules/
redhen_relation/ includes/ redhen_relation.forms.inc - Return a form array for adding/editing a connection.
File
- modules/
redhen_contact/ includes/ redhen_contact.forms.inc, line 15 - Forms for creating, editing, and deleting contacts.
Code
function redhen_contact_contact_form($form, &$form_state, $contact) {
// Ensure this include file is loaded when the form is rebuilt from the cache.
$form_state['build_info']['files']['form'] = drupal_get_path('module', 'redhen_contact') . '/includes/redhen_contact.forms.inc';
// Add the default field elements.
$form['name'] = array(
'#type' => 'container',
);
$form['name']['first_name'] = array(
'#type' => 'textfield',
'#title' => t('First name'),
'#default_value' => $contact->first_name,
'#maxlength' => 255,
'#required' => variable_get(REDHEN_CONTACT_REQUIRE_FIRST_NAME, TRUE),
'#weight' => -6,
);
$form['name']['middle_name'] = array(
'#type' => 'textfield',
'#title' => t('Middle name'),
'#default_value' => $contact->middle_name,
'#maxlength' => 255,
'#weight' => -6,
);
$form['name']['last_name'] = array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#default_value' => $contact->last_name,
'#maxlength' => 255,
'#required' => TRUE,
'#weight' => 5,
);
// Add the field related form elements.
$form_state['redhen_contact'] = $contact;
field_attach_form('redhen_contact', $contact, $form, $form_state);
// Display asterisk if the field is required.
if (isset($form['redhen_contact_email'])) {
$form['redhen_contact_email'][$form['redhen_contact_email']['#language']]['#required'] = redhen_contact_user_email_setting(REDHEN_CONTACT_REQUIRE_EMAIL, $contact);
}
$form['actions'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'form-actions',
),
),
'#weight' => 40,
);
// We add the form's #submit array to this button along with the actual submit
// handler to preserve any submit handlers added by a form callback_wrapper.
$submit = array(
'redhen_contact_contact_form_submit',
);
if (!empty($form['#submit'])) {
$submit = array_merge($submit, $form['#submit']);
}
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save contact'),
'#submit' => $submit,
);
// We append the validate handler to #validate in case a form callback_wrapper
// is used to add validate handlers earlier.
$form['#validate'][] = 'redhen_contact_contact_form_validate';
return $form;
}