Hi all. I am trying to make a form where some external content is loaded into a div element through AHAH when a button is clicked.

The following screenshot of firebug shows that I actually received a response:
http://clip2net.com/clip/m6360/1211907941-clip-28kb.png

The following screenshot shows the error message I receive when clicking on the button:
http://clip2net.com/clip/m6360/1211908061-clip-9kb.png
(It says
An error occurred.
/drupal/sites/all/modules/poster/poster.generate.php
(no information available).

)

Below is the snippet of code for the form I generated.

	$form['preview'] = array(
		'#type' => 'button',
		'#value' => t('Preview'),
		'#ahah' => array(
			'path' => drupal_get_path('module', 'poster') . '/poster.generate.php',
			'wrapper' => 'poster-preview',
			'method' => 'replace',
			'effect' => 'fade'
		)
	);
	$form['poster-preview'] = array(
		'#type' => 'markup',
		'#value' => '<div id="poster-preview"></div>'
	);
	return $form;

What format does AHAH expect when it gets a response? JSON? HTML? Text? Any format?

Does anyone know why this isn't working? Thanks ahead of time!

Comments

alexmut’s picture

Did anybody explain your this error?

shawngo’s picture

I ran into this same situation - here is my (untested) solution:

<?php
function mymodule_myform() {
// ...
    $form['preview'] = array(
        '#type' => 'button',
        '#value' => t('Preview'),
        '#ahah' => array(
            'path' => 'mymodule_js', // its expecting a menu item defined in hook_menu with a callback function
            'wrapper' => 'poster-preview',
            'method' => 'replace',
            'effect' => 'append' // i needed to append information
        )
    );
    $form['poster-preview'] = array(
        '#type' => 'markup',
        '#value' => '<div id="poster-preview"></div>'
    );
// ...
    return $form;
}

function mymodule_menu() {
  $items['mymodule_js'] = array(
    'title' => 'ahah title',
    'page callback' => 'mymodule_js',
    'page arguments' => $_POST, // demonstration purposes only
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

// this is where i was running into issues
function mymodule_js($args = array()) {
  $output = print_r($args, TRUE); // demonstration purposes only
  // print to screen the data in json format
  drupal_json(array('status' => TRUE, 'data' => $output));
}

?>