How to create dynamic multi column forms using native form module? I am looking to find out how I can create a form which the definition of the form is coming from a REST API as a JSON object. The form can be 1 column, 2 columns or 10 columns.

I have been able to do this by just using the native table theming option, but I want to be able to do this with the native form options so that I can utilize all the validations and everything else etc.

Does anyone have an idea as to how I can accomplish a multi-column dynamic form?

Thanks in advance!
The way you group form items (as you will need to do to create a single column) is to use the FAPI grouping mechanism, which is described here :

https://www.drupal.org/node/262758

then you can use a loop and some vars to name them, for example :

&lt;?php

  // How ever many columns your rest callback wants to make.
  $col_limit = 10;

  for ($x = 0, $x &lt; $col_limit, $x++) {
    $form["group_$x"] = array(
      '#type' =&gt; 'fieldset',
      '#title' =&gt; t('Your Name'),
      '#collapsible' =&gt; FALSE,
      '#collapsed' =&gt; FALSE,
    );
    $form["group_$x"]["first_name_$x"] = array(
      '#type' =&gt; 'textfield',
      '#title' =&gt; t('First Name'),
    );
    $form["group_$x"]["last_name_$x"] = array(
      '#type' =&gt; 'textfield',
      '#title' =&gt; t('Last Name'),
    );
  }

  $form["col_limit"] = array(
    '#type' =&gt; 'hidden',
    '#value' =&gt; $col_limit,
  );

?&gt;


Will create 10 groups, with form items.
You can then use CSS or jQuery to create columns or tabs or format how ever you wish.

The hidden variable is there to tell you submit handler how many coumns there are and therefore how many times it has to loop looking for 

$form_state['values']["last_name_$x"]