Integrating Marketo Munchkin with your Webforms is a two-step process: first you have to tell the Marketo Munchkin module you want to submit some user data and then you have to assign that data to the appropriate fields for transmission. For step one we will use a custom submit handler with our webform. Our submit handler will tell the Marketo Munchkin module we want to submit some user data and it will pull that data from the form_state:

MY_MODULE.module

/**
 * Implementation of hook_form_alter().
 */
function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
  // Add validation for a particular Webform node:
  if ($form_id == 'webform_client_form_1') {
    // Add the submit handler after the existing Webform submit handler,
    // but before the second Webform handler. Pop off the first one and add
    // ours second.
    $first = array_shift($form['#submit']);
    array_unshift($form['#submit'], $first, 'example_webform_submit');
  }
}
/**
* Submit handler for Webform ID #1.
*/
function example_webform_submit(&$form, &$form_state) {
  global $user;
  
  $munchkin_secret_key = variable_get('munchkin_secret_key', '');
  // Make sure the secret key is set in the configs before setting session data.
  // Exclude logged in users as we only want anonymous users being tracked.
  if (!empty($munchkin_secret_key) && $user->uid < 1) {
    $anons_email = $form_state['values']['submitted']['1'];
    $anons_msg = $form_state['values']['submitted']['2'];
    // Submission type used to create Lead data array.
    $_SESSION['marketo-munchkin-submit'] = 'example_webform';
    // Email address to link the Lead data to.
    $_SESSION['marketo-munchkin-data-user_email'] = $anons_email;
    
    // create a session var to store the message
    $_SESSION['marketo-munchkin-data-user_msg'] = $anons_msg;
    
    drupal_set_message('Thank you for joining our email list!', 'status');
  }
  
}

In example_webform_submit() we first verify that the Munchkin secret key has been set and, for this example, that the data is coming from an anonymous user. Our webform was only grabbing the user's email address and a short message. We want to send the user message to our Marketo account and have it associated with the user's email address so we need to pull that data from the form. Next we tell the Marketo Munchkin module what type of data submission we are doing. This value is arbitrary and is used as the TYPE for some Marketo hooks. The absolute minimum amount of data we can pass to Marketo Munchkin is an email address. The module uses the $_SESSION variable 'marketo-munchkin-data-user_email' to store this information. We also want to transmit the message from this user so we create our own $_SESSION variable to hold that data. For step two we implement hook_marketo_create_TYPE_data():

MY_MODULE.module

/**
 * @Function
 * Implements hook_marketo_create_TYPE_data().
 */
function MY_MODULE_marketo_create_example_webform_data(&$munchkin_data) {
  $munchkin_data['Message'] = $_SESSION['marketo-munchkin-data-user_msg'];
  
  unset($_SESSION['marketo-munchkin-data-user_msg']);
}

Here we add our data to the $munchkin_data array. This is an associative array where the key represents the name of the Marketo data field, 'FirstName', 'LastName', or 'Title' for instance. You can use any field defined in you Marketo.com account. For our example, assume we have a custom field called 'Message.' We assign our data and then clean up the $_SESSION data we no longer need. On the very next page load the Marketo Munchkin module will format the data and add it to the page as JavaScript.