1 contact.admin.inc contact_category_edit_form($form, &$form_state, array $category = array())

Form constructor for the category edit form.

Parameters

array $category: An array describing the category to be edited. May be empty for new categories. Recognized array keys are:

  • category: The name of the category.
  • recipients: A comma-separated list of recipients.
  • reply: (optional) The body of the auto-reply message.
  • weight: The weight of the category.
  • selected: Boolean indicating whether the category should be selected by default.
  • cid: The category ID for which the form is to be displayed.

See also

contact_menu()

contact_category_edit_form_validate()

contact_category_edit_form_submit()

Related topics

File

core/modules/contact/contact.admin.inc, line 284
Admin page callbacks for the Contact module.

Code

function contact_category_edit_form($form, &$form_state, array $category = array()) {
  if (empty($category)) {
    backdrop_set_title(t('Add contact form category'));
  }

  // If this is a new category, add the default values.
  $category += array(
    'category' => '',
    'recipients' => '',
    'reply' => '',
    'weight' => 0,
    'selected' => 0,
    'cid' => NULL,
  );

  // Get contact_default_category.
  $config_data = contact_config_data();
  $default_category = $config_data['contact_default_category'];

  $form['category'] = array(
    '#type' => 'textfield',
    '#title' => t('Category'),
    '#maxlength' => 255,
    '#default_value' => $category['category'],
    '#description' => t("Example: 'website feedback' or 'product information'."),
    '#required' => TRUE,
  );
  $form['recipients'] = array(
    '#type' => 'textarea',
    '#title' => t('Recipients'),
    // Recipients are stored comma-separated, but display with new lines for
    // better human readability.
    '#default_value' => implode("\n", explode(',', $category['recipients'])),
    '#description' => t("To specify multiple recipients, separate each email address with a new line, comma, semicolon or space."),
    '#placeholder' => t("admin@example.com\nsales@example.com"),
    '#required' => TRUE,
    '#rows' => max(5, sizeof(explode(',', $category['recipients'])) + 2),
  );
  $form['reply'] = array(
    '#type' => 'textarea',
    '#title' => t('Auto-reply'),
    '#default_value' => $category['reply'],
    '#description' => t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),
  );
  $form['weight'] = array(
    '#type' => 'hidden',
    '#value' => $category['weight'],
  );
  $form['selected'] = array(
    '#type' => 'select',
    '#title' => t('Selected'),
    '#options' => array(
      0 => t('No'),
      1 => t('Yes'),
    ),
    '#default_value' => (isset($category['cid']) && $default_category == $category['cid']),
    '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
  );
  $form['cid'] = array(
    '#type' => 'hidden',
    '#value' => $category['cid'],
  );
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['actions']['cancel'] = array(
    '#type' => 'link',
    '#title' => t('Cancel'),
    '#href' => 'admin/structure/contact',
    '#options' => array(
      'attributes' => array(
        'class' => array('form-cancel')
      ),
    ),
  );

  return $form;
}