How to get the attribute value and remove if it is empty in form_state D8?

by latikas   Last Updated November 15, 2017 06:07 AM

I am trying to remove the value(_blank) of attribute['target'] variable in form_state when the value I get empty i.e. when the checkbox is unselected.

enter image description here

public function submitForm(array &$form, FormStateInterface $form_state) {
$response = new AjaxResponse();

if ($form_state->getErrors()) {
  unset($form['#prefix'], $form['#suffix']);
  $form['status_messages'] = [
    '#type' => 'status_messages',
    '#weight' => -10,

  $response->addCommand(new HtmlCommand('#linkit-editor-dialog-form', $form));

else {
  // This was I tried      
    $form_state->setValue($form_state['attributes']['target'], "_TEST");
    #$form_state->setValue('attributes', "_TEST");
    #$form_state->setValueForElement('target', "_TEST");

  // End
  $response->addCommand(new EditorDialogSave($form_state->getValues()));
  $response->addCommand(new CloseModalDialogCommand());

return $response;


After execution the code I got wrong array

enter image description here

Any help? Thanks in advance.

Tags : 8 forms

Related Questions

Reuse form from another module in multistep form

Updated May 21, 2015 22:03 PM