With normal FAPI AHAH you can use drupal_json(array( ... )); in your menu callback function in order to return html to the form. What is the equivalent mechanism in AHAH helper?

Comments

20th’s picture

With AHAH helper you should use a ahah_helper_path function, as in example ahah_helper_demo.module, which can be found in the module folder.
Like everywhere else AHAH helper also uses drupal_json(array( ... )); in a callback function.

entrigan’s picture

I thought the idea was that ahah_helper_path() makes the form use the default submit handler rather than a special callback function. So I guess what I am asking is where does the "return drupal_json(...)" go?

20th’s picture

drupal_json() is called at the end of ahah_helper_render() function. This is a page callback function registered to the 'ahah_helper/' menu path. This function performs some routine actions and rebuilds the form.

drupal_json() generates output that is sent to the user without modifications.

entrigan’s picture

Thanks for all your help :)

Ok so I found the ahah_helper_render() function, and I see the drupal_json() call. However it looks like it is hardcoded to return theme(status_messages). Is there no way to provide additional HTML ?

20th’s picture

I think there are two ways to do that, without modifying source code.
You can insert your html directly into the form. You gonna need hook_form_alter or hook_form_ID_alter to do that. Simply add a new element to the form like this:

function mymodule_form_alter(&$form, $form_state) {
  $form['my_custom_html'] = array(
    '#value' => 'html here',
    '#weight' => 40,
  );
}

Whatever you put into #value is rendered without changes. The #weight parameter can control the position of you html in the form. With different #weight values you can put it at the beginning, end, or somewhere in the middle.

Or you can implement you own 'status_messages' hook in your theme, that will output these messages as usual, and add some html when you need it.
This is not the best idea, but still should work.

entrigan’s picture

Status: Active » Fixed

That makes alot of sense. Not sure why I did not think of the hook_form_alter approach. Thanks for the help :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.