0

I have created a content type Article including the fields Field 1, Field 2, Field 3 ......

All these fields have multiple values. I also created the custom template for this content type.

Now I want to display all fields of the form in a table and use only one button Add another item to add a line for all the fields.

enter image description here

1

Add the following snippet in template.php of your active theme;

<?php
function THEMENAME_theme($existing, $type, $theme, $path) {
    return array(
        'article_node_form' => array(
            'arguments' => array('form' => NULL),
            'template' => 'node--add--article',
            'render element' => 'form',
            ),
    );
}
?>

Then create a template file called node--add--article.tpl.php (same as the 'template' field in template.php.)

This is node--add--article.tpl.php:

<table >
  <tr>
    <td><?php print drupal_render_children($form['field_1']); ?></td>
    <td><?php print drupal_render_children($form['field_2']);  ?></td>
    <td><?php print drupal_render_children($form['field_3']);  ?></td>
  </tr>
</table>


<?php print drupal_render_children($form);  ?>

Now Clear Cache and see the result.

| improve this answer | |
  • If you do so, then under each field will have a button "add another item" – Lê Quang Tú Jul 28 '15 at 8:28
0

You need to use field group multiple module

And for displaying that as table you can add to that module field group table module

| improve this answer | |
  • I have tried using multiple group field module but I encountered some problems with it: - I can not delete a row when I accidentally add another item - When you do not enter a value for the first row, but only enter a value for the second row after submit. It will automatically push data up the second row in the first row. – Lê Quang Tú Jul 28 '15 at 7:48
  • - Since I created the template for the form and add the node node template should I encountered some problems with it when it displays in node node add form and template – Lê Quang Tú Jul 28 '15 at 7:48
  • You could try [field collection module] (drupal.org/project/field_collection) , the best way is to have node separated from that fields. for example you can create entity with that fields and attach it to the node using reference field and add on the top of it something like inline entity form. Keep in mind field_collection is entity – Ziftman Jul 28 '15 at 19:06
0

Try to use the Css Column Property to distribute them as table or use the combination of modules Panels & Panelizer (try the first option, it might be lighter to implement).

| improve this answer | |
  • These are just some of the data included in the content type of me. There are many other data fields displayed in different structures. Can I apply under your guidance? – Lê Quang Tú Jul 28 '15 at 4:44
  • Sorry I didn't understand your last question. – user16289 Jul 28 '15 at 5:33
0

try this Field Collection Table it work with: Field collection

Regards

| improve this answer | |

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.