if (!empty($element['#id'])) { $output .= ' id="'. $element['#id'] .'-wrapper"'; } else { // if we can't get the #id from $element['#id'] just build it from $element['#name'] $id=explode("[value]", $element['#name']); $output .= ' id="'. $id[0] .'-wrapper"'; }