0

I created a form for my module. I have a formatted text box

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

When I try to save the form message comes back as an array and I don't know how to pull the value out of it.

public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
    \Drupal::logger('td')
      ->notice('text: @message', array('@message' => $form_state->getValue('message'),));
  }
1

Try with:

$message = $form_state->getValue('message')['value'];
  • That's it. Not sure why but I was trying to ->value like if it was a node object. – Tyler Jan 28 at 22:45

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.