Change ID of webform hidden element
I had a similar issue to deal with. I need to generate form IDs programmatically so I implemented below code.

function voci_comment_form($form, &amp;$form_state, $cid) {
     $form['#attributes']['id'] = 'voci-comment-form-' . $cid;
     $form['#attributes']['class'][] = 'voci-comment-form';
     $form['body'] = array(
      '#title' =&gt; 'Post a comment',
      '#type' =&gt; 'textarea',
      '#resizable' =&gt; FALSE,
      '#rows' =&gt; 1,
     );
     $form['comment'] = array(
      '#type' =&gt; 'submit',
      '#value' =&gt; 'Comment',
     );

      return $form;
   }


It's true that you can set $element['#attributes']['id'] and that will apply to the form field. 

I hope this helps... :)