How can I theme field collection forms? I have a field_field_collection in content type (used to field collection module and have unlimited value). It has a number of fields as in the picture below:


And I want customize theme for it as template as in the picture below:


How I can I achieve that? I tried to write a template for it, but the result is bad. When I click "add another item" the result looks like shown in the picture under my code below.

Here is my code:

    &lt;?php
    kpr($form);
    print drupal_render($form['title']);
    $i = 0;
    foreach($form['field_field_collection']['und'] as $items){
    if(isset($form['field_field_collection']['und'][$i])) {
        ?&gt;
        &lt;table border="1" cellpadding="10"&gt;
            &lt;tbody&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;?php
                    print drupal_render($form['field_field_collection']['und'][$i]['field_field_01']);
                    ?&gt;
                &lt;/td&gt;
                &lt;td&gt;
                    &lt;?php
                    print drupal_render($form['field_field_collection']['und'][$i]['field_field_02']);
                    ?&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;?php
                    print drupal_render($form['field_field_collection']['und'][$i]['field_field_3']);
                    ?&gt;
                &lt;/td&gt;
                &lt;td&gt;
                    &lt;?php
                    print drupal_render($form['field_field_collection']['und'][$i]['field_field_4']);
                    ?&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;/tbody&gt;
        &lt;/table&gt;
    &lt;?php
        $i++;
        }
    }
?&gt;
&lt;?php
    print drupal_render($form['field_field_collection']['und']['add_more']);
    hide($form['actions']);
    hide($form['additional_settings']);
    print drupal_render_children($form);
?&gt;


And here is the result when I click "add another item":
If your requirement is to format Field Collection in Table Format, then Field Collection Table Module will help.