using formBuilder()->getForm() doesn't allow text_area to be passed to submit handler

Created on 6 August 2018, over 6 years ago
Updated 29 January 2024, 11 months ago

I created a form that I wanted to be reusable. So I created the form below to imported it into a add form and a edit form. Please be aware I do have the validateForm, and submitForm function in my code.

class PaneConfigurationForm extends ConfigFormBase {

    /**
     * {@inheritdoc}
     */
    public function getFormId() {
        return 'admin_pane_settings';
    }

    /**
     * {@inheritdoc}
     */
    public function buildForm(array $form, FormStateInterface $form_state, $element = null) {

       $form['description'] = array(
          '#type' => 'text_format',
          '#title' => 'description',
          '#default_value' => '<p>The quick brown fox jumped over the lazy dog.</p>',
          '#value' => '<p>The quick brown fox jumped over the lazy dog.</p>',
          '#format' => 'full_html',
       );

       return parent::buildForm($form, $form_state);
    }
}

So in my AddPane form I use the \Drupal::formBuilder()->getForm() function to get the form and apply it to my parent form. For some reason when I submit the form the value is not passed to the submit handler, only to form format is. Other fields seem to work fine, just not text_format.

class AddPaneForm extends Formbase {

    /**
     * {@inheritdoc}
     */
    public function getFormId() {
        return 'add_admin_pane';
    }

    /**
     * {@inheritdoc}
     */
    public function buildForm(array $form, FormStateInterface $form_state, $element = null) {


          $form = \Drupal::formBuilder()->getForm('Drupal\_module_\Form\PaneConfigurationForm');

          $form['actions']['submit'] = array(
            '#type' => 'submit',
            '#value' => $this->t('Save'),
          );
    }

    public function submitForm(array &$form, FormStateInterface $form_state)
    {
          $form_state->getValue('description')
    }
}
πŸ’¬ Support request
Status

Closed: outdated

Version

9.5

Component
FormΒ  β†’

Last updated about 5 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States jalite1991

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    Could the issue here be that there is no return inside the ::buildForm function of AddPaneForm?

    Could you try replicate this with a simple module and only Drupal core and see if it works?

  • Status changed to Closed: outdated 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Since there hasn't been a follow up going to close out for now.

Production build 0.71.5 2024