Hi folks,
I have an issue when tying to alter a form using hook_form_alter() on a form that is being opened in a modal via the use-ajax link.

I have a link that opens a modal using 'use-ajax' which works fine without any hook_form_alter(), but the moment I use hook_form_alter in my custom .module file, the form returns a AJAX HTTP error.

I've tried to add a form prefix and suffix to wrap the module. This is my basic hook_form_alter()

function ahs_form_handler_form_alter(&$form, $form_state, $form_id) {
  $form['#prefix'] = '<div id="myform-ajax-wrapper">';
  $form['#suffix'] = '</div>';
  echo '<h2>FORM DATA</h2>';

  return $form;
}

Any help is appreciated.

Comments

Thinkingbox-Tien created an issue. See original summary.

valthebald’s picture

Priority: Major » Normal
Status: Active » Closed (works as designed)

It's echo() that breaks AJAX output. You should modify $form array, but not output anything.