3

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: enter image description here

And I want customize theme for it as template as in the picture below: enter image description here

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:

    <?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])) {
        ?>
        <table border="1" cellpadding="10">
            <tbody>
            <tr>
                <td>
                    <?php
                    print drupal_render($form['field_field_collection']['und'][$i]['field_field_01']);
                    ?>
                </td>
                <td>
                    <?php
                    print drupal_render($form['field_field_collection']['und'][$i]['field_field_02']);
                    ?>
                </td>
            </tr>
            <tr>
                <td>
                    <?php
                    print drupal_render($form['field_field_collection']['und'][$i]['field_field_3']);
                    ?>
                </td>
                <td>
                    <?php
                    print drupal_render($form['field_field_collection']['und'][$i]['field_field_4']);
                    ?>
                </td>
            </tr>
            </tbody>
        </table>
    <?php
        $i++;
        }
    }
?>
<?php
    print drupal_render($form['field_field_collection']['und']['add_more']);
    hide($form['actions']);
    hide($form['additional_settings']);
    print drupal_render_children($form);
?>

And here is the result when I click "add another item":

enter image description here

  • Did you find any solution ? If yes then please share here. – visabhishek May 3 '16 at 12:15
  • You didn't find any solution? – Danz Jan 31 '18 at 10:09
-2

If your requirement is to format Field Collection in Table Format, then Field Collection Table Module will help.

  • Field Collection Table module can not help me – Lê Quang Tú Sep 28 '15 at 8:05
  • That's for frontend display, OP wants node form. – leymannx Jan 18 '19 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.