Can I strip my form of some classes and DIVs? Can I strip my form of these classes and DIVs as shown in the code below?

&lt;form action="/example/unsubscribe" method="post" id="exampleform-unsubscribe" accept-charset="UTF-8"&gt;
  &lt;div&gt;/** this div **/
    &lt;div class="form-item form-type-textfield form-item-email"&gt;/** strip these class and add my own class? **/
      &lt;label for="edit-email"&gt;E-mail address &lt;span class="form-required" title="This field is required."&gt;*&lt;/span&gt;&lt;/label&gt;/** strip classes form-required from span **/
      &lt;input type="text" id="edit-email" name="email" value="" size="60" maxlength="128" class="form-text required" /&gt;/** strip form-text and required class **/
    &lt;/div&gt;
    &lt;input type="submit" id="edit-submit" name="op" value="Remove me!" class="form-submit" /&gt;/** remove form-submit class **/ &lt;input type="hidden" name="form_build_id" value="formjKkl1KLWJLnv0hM4DSVd8-40boTgBQAzWWhUn44c15Q" /&gt;
    &lt;input type="hidden" name="form_token" value="LB07DqsDXK9idWdOHLxUen7jKxm52JqTyHiR7-pNumA" /&gt;
    &lt;input type="hidden" name="form_id" value="exampleform_unsubscribe" /&gt;
  &lt;/div&gt;/** this div **/
&lt;/form&gt;


Would it affect any form or ajax form functions of the form?
There are 2 Drupal theme functions which you need to override in your theme's template.php

You can paste this code in your theme's template.php and change "themename" to the name of your theme (Drupal 7 code):

It shouldn't affect any ajax form functions if you have a custom theme, however if you are using a contributed theme you should check the javascript files to see if there are any functions using the classes / selectors you have stripped out.


Override theme_form() to remove the div

function themename_form($variables) {
  $element = $variables['element'];
  if (isset($element['#action'])) {
    $element['#attributes']['action'] = drupal_strip_dangerous_protocols($element['#action']);
}
element_set_attributes($element, array('method', 'id'));
if (empty($element['#attributes']['accept-charset'])) {
 $element['#attributes']['accept-charset'] = "UTF-8";
}
return '' . $element['#children'] . '';
}
Override theme_form_element() function to strip out the classes


function themename_form_element($variables) {
  $element = &amp;$variables['element'];
  $element += array(
    '#title_display' => 'before',
  );
  if (isset($element['#markup']) &amp;&amp; !empty($element['#id'])) {
    $attributes['id'] = $element['#id'];
  }
  // Remove line below if you don't want a custom class
  $attributes['class'] = array('your-custom-class'); 

// Add a class for disabled elements to facilitate cross-browser styling.
  if (!empty($element['#attributes']['disabled'])) {
    $attributes['class'][] = 'form-disabled';
  }
  $output = '' . "\n";
  // If #title is not set, we don't display any label or required marker.
  if (!isset($element['#title'])) {
    $element['#title_display'] = 'none';
  }

$prefix = isset($element['#field_prefix']) ? '' .   $element['#field_prefix'] . ' ' : '';

$suffix = isset($element['#field_suffix']) ? ' ' . $element['#field_suffix'] . '' : '';

switch ($element['#title_display']) {
    case 'before':
    case 'invisible':
      $output .= ' ' . theme('form_element_label', $variables);
      $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
      break;

case 'after':
  $output .= ' ' . $prefix . $element['#children'] . $suffix;
  $output .= ' ' . theme('form_element_label', $variables) . "\n";
  break;

case 'none':
case 'attribute':
  // Output no label and no required marker, only the children.
  $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
  break;


}

if (!empty($element['#description'])) {
    $output .= '' . $element['#description'] . "\n";
  }

$output .= "\n";

return $output;
}