'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_desc_end'] = array( '#type' => 'textfield', '#title' => t('Contact description'), '#description' => t('This text will show at the bottom of the Author Contact block, can be used for reminder instructions, thanks etc.'), '#default_value' => variable_get('authorcontact_desc_end', '') ); $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 the number of line to dislay in the message form. Standard is 4.'), '#default_value' => variable_get('authorcontact_form_height', 4) ); $form['authorcontact_form_field1'] = array( '#type' => 'textfield', '#title' => t('Extra Field 1'), '#description' => t('Label for Extra Field to display in form. < none> remove it from form. Required Field'), '#default_value' => variable_get('authorcontact_form_field1', 'Field1') ); $form['authorcontact_form_field2'] = array( '#type' => 'textfield', '#title' => t('Extra Field 2'), '#description' => t('Label for Extra Field to display in form. < none> remove it from form. Required Field'), '#default_value' => variable_get('authorcontact_form_field2', 'Field2') ); $form['authorcontact_form_field3'] = array( '#type' => 'textfield', '#title' => t('Extra Field 3'), '#description' => t('Label for Extra Field to display in form. < none> remove it from form.'), '#default_value' => variable_get('authorcontact_form_field3', 'Field3') ); $form['authorcontact_form_field4'] = array( '#type' => 'textfield', '#title' => t('Extra Field 4'), '#description' => t('Label for Extra Field to display in form. < none> remove it from form.'), '#default_value' => variable_get('authorcontact_form_field4', 'Field4') ); $form['authorcontact_form_field5'] = array( '#type' => 'textfield', '#title' => t('Extra Field 5'), '#description' => t('Label for Extra Field to display in form. < none> remove it from form. Required Field'), '#default_value' => variable_get('authorcontact_form_field5', 'Field5') ); $form['authorcontact_form_field6'] = array( '#type' => 'textfield', '#title' => t('Extra Field 6'), '#description' => t('Label for Extra Field to display in form. < none> remove it from form.'), '#default_value' => variable_get('authorcontact_form_field6', 'Field6') ); $form['authorcontact_form_checkbox1'] = array( '#type' => 'textfield', '#title' => t('Check Box Label'), '#description' => t('Label for checkbox to display in form. < none> remove it from form. Required Field (not working, need to install checkbox_validate module)'), '#default_value' => variable_get('authorcontact_form_checkbox1', 'I Agree') ); $form['authorcontact_form_checkbox2'] = array( '#type' => 'textfield', '#title' => t('Check Box Label'), '#description' => t('Label for checkbox to display in form. < none> remove it from form.'), '#default_value' => variable_get('authorcontact_form_checkbox2', 'I Agree not mandatory') ); //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_desc_end', $edit['authorcontact_desc_end']); variable_set('authorcontact_form_width', $edit['authorcontact_form_width']); variable_set('authorcontact_form_height', $edit['authorcontact_form_height']); variable_set('authorcontact_form_field1', $edit['authorcontact_form_field1']); variable_set('authorcontact_form_field2', $edit['authorcontact_form_field2']); variable_set('authorcontact_form_field3', $edit['authorcontact_form_field3']); variable_set('authorcontact_form_field4', $edit['authorcontact_form_field4']); variable_set('authorcontact_form_field5', $edit['authorcontact_form_field5']); variable_set('authorcontact_form_field6', $edit['authorcontact_form_field6']); variable_set('authorcontact_form_checkbox1', $edit['authorcontact_form_checkbox1']); variable_set('authorcontact_form_checkbox2', $edit['authorcontact_form_checkbox2']); 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'); $block['content'] .= t('
') . variable_get('authorcontact_desc_end', '') . t('
'); 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, // '#element_validate' => array('authorcontact_form_name_validate') ); $form['senderemail'] = array( '#title' => t('Email'), '#type' => 'textfield', '#size' => variable_get('authorcontact_form_width', 15), '#required' => true, '#element_validate' => array('authorcontact_form_validate') ); if ( variable_get('authorcontact_form_field1', '') <> '' ) { $form['senderfield1'] = array( '#title' => t(variable_get('authorcontact_form_field1', 'Phone')), '#type' => 'textfield', // '#default_value' => t(variable_get('authorcontact_form_field1', 'Phone')), '#size' => variable_get('authorcontact_form_width', 15), '#required' => true ); }; if ( variable_get('authorcontact_form_field2', '') <> '' ) { $form['senderfield2'] = array( '#title' => t(variable_get('authorcontact_form_field2', 'Phone 2')), '#type' => 'textfield', '#size' => variable_get('authorcontact_form_width', 15), '#required' => true ); }; if ( variable_get('authorcontact_form_field3', '') <> '' ) { $form['senderfield3'] = array( '#title' => t(variable_get('authorcontact_form_field3', 'Field3')), '#type' => 'textfield', '#size' => variable_get('authorcontact_form_width', 15), '#required' => false ); }; if ( variable_get('authorcontact_form_field4', '') <> '' ) { $form['senderfield4'] = array( '#title' => t(variable_get('authorcontact_form_field4', 'Field4')), '#type' => 'textfield', '#size' => variable_get('authorcontact_form_width', 15), '#required' => false ); }; if ( variable_get('authorcontact_form_field5', '') <> '' ) { $form['senderfield5'] = array( '#title' => t(variable_get('authorcontact_form_field5', 'Field5')), // '#default_value' => t(variable_get('authorcontact_form_field5', 'Phone')), '#type' => 'textfield', '#size' => variable_get('authorcontact_form_width', 15), '#required' => true ); }; if ( variable_get('authorcontact_form_field6', '') <> '' ) { $form['senderfield6'] = array( '#title' => t("6".variable_get('authorcontact_form_field6', 'Field6')), // '#default_value' => t(variable_get('authorcontact_form_field6', 'Phone')), '#type' => 'textfield', '#size' => variable_get('authorcontact_form_width', 15), '#required' => false ); }; //because of checkbox bug the required red x will not show and will not be checked //you must add the checkbox_validate module to work as expected if ( variable_get('authorcontact_form_checkbox1', '') <> '' ) { $form['sendercheckbox1'] = array( '#title' => t(variable_get('authorcontact_form_checkbox1', '')), '#type' => 'checkbox', '#return_value' => "Ok", '#required' => true , '#element_validate' => array('authorcontact_form_checkbox1_validate'), ); }; if ( variable_get('authorcontact_form_checkbox2', '') <> '' ) { $form['sendercheckbox2'] = array( '#title' => t(variable_get('authorcontact_form_checkbox2', 'I Agree V2')), '#type' => 'checkbox', '#return_value' => "Ok", '#required' => false ); }; $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 */ //to check element_validate not working with checkbox //function authorcontact_form_name_validate($form_id, $form_values) { // //check the email address is valid // if(isset($form_values['values']['sendername'])) { // if (!valid_email_address($form_values['values']['senderemail'])) { // form_set_error('name', t('The email address you entered is not valid. '. variable_get('authorcontact_form_checkbox1', '') )); // } // } //} 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')); } } } function authorcontact_form_checkbox1_validate($form_id, $form_values) { //check the mandatory checkbox is checked // if($authorcontact_form_checkbox1) { if($form_values['values']['sendercheckbox1'] != "Ok") { form_set_error('', t('You must check the box authorcontact_form_checkbox1. '. variable_get('authorcontact_form_checkbox1', '') )); } // } } /** * 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'], 'senderfield1' => $form_state['values']['senderfield1'], 'senderfield2' => $form_state['values']['senderfield2'], 'senderfield3' => $form_state['values']['senderfield3'], 'senderfield4' => $form_state['values']['senderfield4'], 'senderfield5' => $form_state['values']['senderfield5'], 'senderfield6' => $form_state['values']['senderfield6'], 'sendercheckbox1' => $form_state['values']['sendercheckbox1'], 'sendercheckbox2' => $form_state['values']['sendercheckbox2'], '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 '.t(variable_get('authorcontact_form_field1', 'Field1')) .': @field1 '.t(variable_get('authorcontact_form_field2', 'Field2')) .': @field2 '.t(variable_get('authorcontact_form_field3', 'Field3')) .': @field3 '.t(variable_get('authorcontact_form_field4', 'Field4')) .': @field4 '.t(variable_get('authorcontact_form_field5', 'Field5')) .': @field5 '.t(variable_get('authorcontact_form_field6', 'Field6')) .': @field6 '.t(variable_get('authorcontact_form_checkbox1', 'I Agree')) .': @checkbox1 '.t(variable_get('authorcontact_form_checkbox2', 'I Agree')) .': @checkbox2 Enquiry: @comment', array( '@sitename' => variable_get('site_name', t('')), '@nodetitle' => $params['nodetitle'], '@referer' => $params['referer'], '@name' => $params['sendername'], '@email' => $params['senderemail'], '@field1' => $params['senderfield1'], '@field2' => $params['senderfield2'], '@field3' => $params['senderfield3'], '@field4' => $params['senderfield4'], '@field5' => $params['senderfield5'], '@field6' => $params['senderfield6'], '@checkbox1' => $params['sendercheckbox1'], '@checkbox2' => $params['sendercheckbox2'], '@comment' => $params['sendercomment'] )); break; } } //should try to have something like tat working inside the mail to not send form_field where label is //'.if(variable_get('authorcontact_form_field1', 'Field1') <> ''){t(variable_get('authorcontact_form_field1', 'Field1') .': @field1;'}' //'.if(variable_get('authorcontact_form_field2', 'Field2') <> ''){t(variable_get('authorcontact_form_field2', 'Field2') .': @field2;'}' //'.if(variable_get('authorcontact_form_field3', 'Field3') <> ''){t(variable_get('authorcontact_form_field3', 'Field3') .': @field3;'}' //'.if(variable_get('authorcontact_form_field4', 'Field4') <> ''){t(variable_get('authorcontact_form_field4', 'Field4') .': @field4;'}' //'.if(variable_get('authorcontact_form_field5', 'Field5') <> ''){t(variable_get('authorcontact_form_field5', 'Field5') .': @field5;'}' //'.if(variable_get('authorcontact_form_field6', 'Field6') <> ''){t(variable_get('authorcontact_form_field6', 'Field6') .': @field6;'}' //'.if(variable_get('authorcontact_form_checkbox1', 'I Agree') <> ''){t(variable_get('authorcontact_form_checkbox1', 'I Agree') .': @checkbox1;'}' //'.if(variable_get('authorcontact_form_checkbox2', 'I Agree') <> ''){t(variable_get('authorcontact_form_checkbox2', 'I Agree') .': @checkbox2;'}'