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 ?

  • 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? – autopoietic Sep 8 '16 at 11:16
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, privacy policy and cookie policy

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