0

In a custom module, I create a new form. In the buildForm function, I define my form :

$form["planet"] = array(
  '#type' => 'textfield',
  '#title' => '1 : '.$this->t('planet'),
  '#maxlength' => 64,
  '#size' => 64,
  '#tree' => TRUE,
);

$form["planet"][0] = array(
  '#type' => 'textfield',
  '#title' => '0 : '.$this->t('land'),
  '#maxlength' => 64,
  '#size' => 64,
);

$form["planet"][1] = array(
  '#type' => 'textfield',
  '#title' => '1 : '.$this->t('land'),
  '#maxlength' => 64,
  '#size' => 64,
);

$form['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Submit'),
);

There are 3 fields, but this is the result :

enter image description here

Why there only first field displayed ?

1
  • I am not certain you would be able to render a textfield within a textfield, ie $form["planet"][0] within $form["planet"], what do you need to achieve with the 'hierarchical' aspect of the form? Commented Sep 8, 2016 at 11:16

1 Answer 1

3

You need change type $form["planet"] to fieldset or container. Don't use text field in this case:

$form["planet"] = array(
  '#type' => 'fieldset',
  '#title' => '1 : '.$this->t('planet'),
  '#collapsible' => TRUE, 
  '#collapsed' => FALSE,
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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