You are here

function views_contact_form_contact_form in Views Contact Form 7

Form constructor for the Views contact form.

See also

views_contact_form_contact_form_validate()

views_contact_form_contact_form_submit()

4 string references to 'views_contact_form_contact_form'
views_contact_form_field_formatter_view in ./views_contact_form.module
Implements hook_field_formatter_view().
views_contact_form_handler::render in views/views_contact_form_handler.inc
Render the field.
views_contact_form_mollom_mollom_form_info in modules/views_contact_form_mollom/views_contact_form_mollom.module
Implements hook_mollom_form_info().
views_contact_form_style::render in views/views_contact_form_style.inc
Renders views

File

./views_contact_form.form.inc, line 10

Code

function views_contact_form_contact_form($form, &$form_state, $data) {
  if (db_table_exists('contact')) {
    $count = db_select('contact', 'contact')
      ->fields('contact')
      ->execute()
      ->rowCount();
    if ($count == 0) {
      drupal_set_message(t('Views Contact Form module is disabled because no contact category
           is found. To get this module working properly,
           the <a href="@modulepage">contact module from core</a> needs to be
           enabled and at least <a href="@contactpage">one category must
           exist</a>.
           If you don\'t want the module contact, just enable it, disable it,
           but don\'t uninstall it.', array(
        '@modulepage' => url('admin/modules'),
        '@contactpage' => url('admin/structure/contact'),
      )), 'warning');
      return array();
    }
  }
  else {
    drupal_set_message(t('Views Contact Form module is disabled because the contact
         table doesn\'t exists. To get this module working properly,
         the <a href="@modulepage">contact module from core</a> needs to be
         enabled and at least <a href="@contactpage">one category must
         exist</a>.
         If you don\'t want the contact module from core, just enable it,
         disable it, but don\'t uninstall it.', array(
      '@modulepage' => url('admin/modules'),
      '@contactpage' => url('admin/structure/contact'),
    )), 'warning');
    return array();
  }

  // Load that page even if the module is not enabled.
  module_load_include('inc', 'contact', 'contact.pages');

  // Get Drupal's default contact form by default.
  $form = drupal_retrieve_form('contact_site_form', $form_state);

  // Remove categories business
  if (isset($form['cid'])) {
    unset($form['cid']);
  }

  // Add recipients using type value so it's not rendered on frontend.
  $form['to'] = array(
    '#type' => 'value',
    '#value' => $data,
  );
  return $form;
}