Automatic adding of the subject to the contact form I have the block that is shown in every node of one content type. The block contains the link (the anchor tag) which leads to the page with contact form.

Is it possible to add subject automatically to the contact form depending on which page the user clicked on the link and came to contact form page? The subject would be the title of that page.

I use Webform module for the contact form.
I have created a custom module, but the form_alter can just as well be placed in the theme template file.

function MYMODULE_block_info() {
  $blocks['contact_at_webform_block'] = array(
    'info' =&gt; t('Contact Us'),
  );

  return $blocks;
}

function MYMODULE_block_view($delta = ''){
  $block = array();

  switch ($delta) {
    case 'contact_at_webform_block':
      if (user_access('access content')) {
        $block['subject'] = t('Contact Us');
        $block['content'] = l('Contact Us', 'contact', array('query' =&gt; array('subject' =&gt; drupal_get_title())));
      }
      break;
  }
  return $block;
}

function MYMODULE_form_alter( &amp;$form, &amp;$form_state,$form_id ){
  //dpm($form); dpm($form_id);
  if ($form_id == 'webform_client_form_5') {
    $qp = drupal_get_query_parameters();
    $subject = isset($qp['subject']) ? $qp['subject'] : '';
    $form['submitted']['subject']['#default_value'] = $subject;
  }
}


So the important part of the link in the block is to add the page title as a query parameter, so the href of the anchor will look like this contact?subject=PAGE_TITLE. If you use a block from views or created from the block UI then make sure to output the link in similar fashion.

The form alter code picks up the query parameter and inserts it into the webform subject text field. You will have to adapt the code here as your form id and text field will be different. Install devel module, then uncomment the dpm statement that is relevant. First dpm the value of your $form_id and replace mine (webform_client_form_5) with yours. Then dpm $form and inspect $form['submitted']. Look for your subject field.