This is doing me nut in really. It's sending the email but not picking up the contents of the form... and I don't know why :(

<?php
// $Ids
// Andy Walpole December 30 2010. This creates a form with some HTML5 attributes andy@suburban-glory.com


function html5form_perm(){
    return array('view form / html5form');
} // function onthisdate_perm()


function html5form_menu(){
    $items = array();
    $items['contact-form'] = array( // This creates the URL name
        'title' => t('Contact Us'), // This is the title of the form
        'page callback' => 'html5form_form', // This is called in the next function
        'access arguments' => array('access content'), 'description' => t('Please use the form below to contact us'),
        'type' => MENU_CALLBACK, // Find out more info on menu callback
        );
    return $items;
}


function html5form_form(){

    return drupal_get_form('html5form_contact_form');

}


function html5form_contact_form($form_state){

    $form['group1'] = array('#type' => 'fieldset', '#title' => t('Add your contact details here'),
        '#collapsible' => false, '#collapsed' => false, '#prefix' => t('Details here about the <a href="/">form</a>'),
        );

    // This is the first form element. It's a text field with "contact-name"
    $form['group1']['contact-name'] = array('#type' => 'textfield', '#title' => t('Name'),
        '#attributes' => array("placeholder" => "eg, John Smith", "required" =>
        "required"), '#required' => true,
        //'#default_value' => t('Please place your name here'),
        );


    $form['group1']['contact-email'] = array('#type' => 'textfield', '#title' => t('Email'),
        '#attributes' => array("placeholder" => "eg, john@example.com", "required" =>
        "required"), '#required' => true, );

    $form['group1']['contact-phone'] = array('#type' => 'textfield', '#title' => t('Phone'),
        '#attributes' => array("placeholder" => "eg, 020 8658 6854", "required" =>
        "required"), '#required' => true, );

    $form['group1']['contact-details'] = array('#type' => 'textarea', '#title' => t
        ('Message'), '#attributes' => array("placeholder" => "eg, 020 8658 6854",
        "required" => "required"), '#required' => true, );

    $form['group1']['contact-zipcode'] = array('#type' => 'textfield', '#title' => t
        ('Please leave blank'), '#prefix' => t('<div class="zipcode">'), '#suffix' => t
        ('</div>'), );

    // No form is any good without a submit button
    $form['group1']['submit-name'] = array('#type' => 'submit', '#value' => 'Submit', );

    return $form;

}


// validate function - always ends with _validate
function html5form_contact_form_validate($form_id, &$form_state){

    $email_contact = $form_state['values']['contact-email'];
    // Uses inbuilt valid_email_address function
    if (valid_email_address($email_contact) == false) {

        form_set_error('contact-email', 'Please enter a valid email address');

    }

    $email_zipcode = $form_state['values']['contact-zipcode'];
    // This is a spam trap - if anything is entered here it will be a spam bot
    if (!empty($email_zipcode)) {

        form_set_error('contact-zipcode', 'Please leave this field blank');

    }
}


function html5form_contact_form_submit($form_id, &$form_state){

    html5form_contact_form_send($form_state['values']);
  
}


function html5form_contact_form_send($form_values) {

  $module = 'new_html5form';
  $key = 'html5formcontactform';
  $to = 'andy@suburban-glory.com';
  $from = $form_values['contact-email'];
  $params = $form_values;
  $language = language_default();
  $send = TRUE;

 $result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
  
  if ($result['result'] == TRUE) {
    
    drupal_set_message(t('Your message has been sent. We will endevour to respond to your enquiry as soon as possible'));
    
  } else {
    
    drupal_set_message(t('There was a problem sending your message and it was not sent.'), 'error');
    
  }
}


function html5form_contact_form_mail($key, &$message, $params) {

  if ($key == 'html5formcontactform') { 

      $message['body'][] = $params['contact-details'];
      
  }
}

?>

Comments

deepsoulstarfish’s picture

drupal forms are a steep learning curve for me, let me know if you get this solved!