(Un-) formatting each form element When we declare something like 

$form['textfield'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; 'textfield title',
  '#maxlength' =&gt; 8,
  '#required' =&gt; true,
);


The output will be something like:

&lt;div id="edit-textfield-wrapper" class="form-item"&gt;
  &lt;label for="edit-textfield"&gt;textfield title: &lt;span title="This field is required." class="form-required"&gt;*&lt;/span&gt;&lt;/label&gt;
  &lt;input type="text" class="form-text required" value="" size="60" id="edit-textfield" name="textfield" maxlength="8"&gt;
&lt;/div&gt;


However, I am willing to remove the container div and label from some of my fields, something like this:

&lt;input type="text" class="form-text required" value="" size="60" id="edit-textfield" name="textfield" maxlength="8"&gt;


Is it possible? Are there any examples somewhere?
You just need to implement hook_theme_registry_alter() to change the theme function that is called when theme('form_element') is invoked; normally the invoked theme function is theme_form_element().

function theme_form_element($element, $value) {
  // This is also used in the installer, pre-database setup.
  $t = get_t();

  $output = '&lt;div class="form-item"';
  if (!empty($element['#id'])) {
    $output .= ' id="' . $element['#id'] . '-wrapper"';
  }
  $output .= "&gt;\n";
  $required = !empty($element['#required']) ? '&lt;span class="form-required" title="' . $t('This field is required.') . '"&gt;*&lt;/span&gt;' : '';

  if (!empty($element['#title'])) {
    $title = $element['#title'];
    if (!empty($element['#id'])) {
      $output .= ' &lt;label for="' . $element['#id'] . '"&gt;' . $t('!title: !required', array('!title' =&gt; filter_xss_admin($title), '!required' =&gt; $required)) . "&lt;/label&gt;\n";
    }
    else {
      $output .= ' &lt;label&gt;' . $t('!title: !required', array('!title' =&gt; filter_xss_admin($title), '!required' =&gt; $required)) . "&lt;/label&gt;\n";
    }
  }

  $output .= " $value\n";

  if (!empty($element['#description'])) {
    $output .= ' &lt;div class="description"&gt;' . $element['#description'] . "&lt;/div&gt;\n";
  }

  $output .= "&lt;/div&gt;\n";

  return $output;
}




function mymodule_theme_registry_alter(&amp;$theme_registry) {
  if (isset($theme_registry['form_element']) {
    $theme_registry['form_element']['function'] = "theme_mymodule_form_element";
  }
}


Using the code of theme_form_element(), you can write your own theme function, and remove the HTML tags you don't want. Take in mind that theme('form_element') is invoked for every form element output with the form API; if you want to change the HTML output of just a form element, then you need to check the #type value.
theme_textfield() is the theme function that themes a text field, but it doesn't output the label, or the wrapping &lt;div&gt;, which is already output by theme_form_element().

Alternatively, this can be done in a theme that overrides theme_form_element().
Which approach you should use depends on if you need to alter the output in a specific theme, or for all the themes enabled in your Drupal site; in the latter case, you need to implement the hooks I reported in a module.