'textfield', '#title' => t('Contact description'), '#description' => t('This text will show at the top of the Author Contact block, can be used for instructions etc.'), '#default_value' => variable_get('authorcontact_desc', '') ); $form['authorcontact_form_width'] = array( '#type' => 'textfield', '#title' => t('Form width for name & email'), '#description' => t('You can set here the size of the form width without change in the css #edit-sendername, #edit-senderemail, #edit-sendercomment {width:94%;} '), '#default_value' => variable_get('authorcontact_form_width', 15) ); $form['authorcontact_form_height'] = array( '#type' => 'textfield', '#title' => t('Form height for message'), '#description' => t('You can set here thenumber of line to dislay in the message form. Standard is 4.'), '#default_value' => variable_get('authorcontact_form_height', 4) ); //elari from author_pane $types = node_get_types(); $options = array(); foreach ($types as $type) { $options[$type->type] = $type->name; } $form['authorcontact_block_display_types'] = array( '#type' => 'checkboxes', '#title' => t('Node types to display on'), '#options' => $options, '#default_value' => variable_get('authorcontact_block_display_types', array()), ); //elari return $form; case 'save': variable_set('authorcontact_desc', $edit['authorcontact_desc']); variable_set('authorcontact_form_width', $edit['authorcontact_form_width']); variable_set('authorcontact_form_height', $edit['authorcontact_form_height']); variable_set('authorcontact_block_display_types', $edit['authorcontact_block_display_types']); break; case 'view': if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') { //elari from authorpane // We're on a node page so load the node. $node = $node = menu_get_object(); $allowed_types = variable_get('authorcontact_block_display_types', array()); if (empty($allowed_types[$node->type])) { // Not a type we want to show on. return; } //elari end from authorpane $block['subject'] = t('Contact Author'); $block['content'] = t('
') . variable_get('authorcontact_desc', '') . t('
'); $block['content'] .= drupal_get_form('authorcontact_form'); return $block; } break; } } /** * Define the form for the block */ function authorcontact_form() { $node = node_load(arg(1)); $form['sendername'] = array( '#title' => t('Your name'), '#type' => 'textfield', '#size' => variable_get('authorcontact_form_width', 15), '#required' => true ); $form['senderemail'] = array( '#title' => t('Email'), '#type' => 'textfield', '#size' => variable_get('authorcontact_form_width', 15), '#required' => true, '#element_validate' => array('authorcontact_form_validate') ); $form['sendercomment'] = array( '#title' => t('Comment'), '#type' => 'textarea', '#rows' => variable_get('authorcontact_form_height', 4), '#required' => true ); $form['nodetitle'] = array( '#type' => 'hidden', '#value' => $node->title ); $form['send'] = array( '#type' => 'submit', '#value' => t('Send') ); return $form; } /** * Validate the form */ function authorcontact_form_validate($form_id, $form_values) { //check the email address is valid if(isset($form_values['values']['senderemail'])) { if (!valid_email_address($form_values['values']['senderemail'])) { form_set_error('email', t('The email address you entered is not valid')); } } } /** * Submit the form */ function authorcontact_form_submit($form_id, &$form_state) { $node = node_load(arg(1)); $pageAuthor = user_load(array('uid' => $node->uid)); $to = $pageAuthor->mail; $from = '"' . $form_state['values']['sendername'] . '" <' . $form_state['values']['senderemail'] . '>'; //create email vars $params = array( 'sendername' => $form_state['values']['sendername'], 'senderemail' => $form_state['values']['senderemail'], 'sendercomment' => $form_state['values']['sendercomment'], 'nodetitle' => $form_state['values']['nodetitle'], 'referer' => $_SERVER['HTTP_REFERER'] ); drupal_mail('authorcontact', 'sendcontact', $to, language_default(), $params, $from); //make note drupal_set_message(t('Contact sent from @from.', array('@from' => $form_state['values']['senderemail']))); } function authorcontact_mail($key, &$message, $params) { $language = $message['language']; switch($key) { case 'sendcontact': $message['subject'] = t('Contact via @site', array('@site' => variable_get('site_name', 'Your website'))); $message['body'] = t('You have recieved an enquiry through @sitename on the page @nodetitle at @referer Name: @name Email: @email Enquiry: @comment', array( '@sitename' => variable_get('site_name', t('')), '@nodetitle' => $params['nodetitle'], '@referer' => $params['referer'], '@name' => $params['sendername'], '@email' => $params['senderemail'], '@comment' => $params['sendercomment'] )); break; } }