Hi everyone,

I have made plenty of CTools form wizards and they all work wonderfully (thanks merlin and all!). So far, I had never found a reason to make it an ajax-only (non-modal) wizard. Now that I give that a try, I'm not having any luck.

I need this form to replace a forum board div on the click of a button. That works just fine. The problem is that the 'Next' button has ctools-use-ajax without ctools-use-ajax-processed ever being added. So, upon clicking the button I get json rather than the ajax being processed.

I've tried everything.. Here's the content pane callback that activates the form in the first place:

function ecourses_instant_connection_render($subtype, $conf, $args, $context) {
  ctools_include('ajax');
  drupal_add_js('misc/jquery.form.js');
  ctools_add_js('ajax-responder');
  $items = array(
    l(t('1'), 'ecourse-ic/nojs/1', array(
      'attributes' => array('id' => 'ic-tools-link1', 'class' => 'blue btn-member ctools-use-ajax'))),
    l(t('2'), 'ecourse-ic/nojs/2', array(
      'attributes' => array('id' => 'ic-tools-link2', 'class' => 'blue btn-member ctools-use-ajax'))),
    l(t('3'), 'ecourse-ic/nojs/3', array(
      'attributes' => array('id' => 'ic-tools-link3', 'class' => 'blue btn-member ctools-use-ajax'))),
    l(t('4'), 'ecourse-ic/nojs/4', array(
      'attributes' => array('id' => 'ic-tools-link4', 'class' => 'blue btn-member ctools-use-ajax'))),
    l(t('5'), 'ecourse-ic/nojs/5', array(
      'attributes' => array('id' => 'ic-tools-link5', 'class' => 'blue btn-member ctools-use-ajax'))),
  );
  $content = theme('item_list', $items, null, 'ul', array('class' => 'ic-tool-block'));
  $block = new stdClass();
  $block->title = t('Instant Connection');
  $block->content = $content;
  return $block;
}

and here's my code (without the forms, which are working perfectly if I change it to use modal instead or just use it without ajax):


/**
 * This function sets up the CTools magic for the form. Basically, after making
 * this, you can forget about all repetitive multistep-form handling nonsense.
 */
function ecourses_ebt_ic_tool_wizard($js = FALSE, $step = NULL) {
  require_once(drupal_get_path('module', 'ic') . '/ic.pages.inc');
  drupal_add_css($path .'/ic.css');
  ctools_include('wizard');
  ctools_include('object-cache');
  $brain_state = arg(2);
  $step = arg(3);
  switch ($brain_state) {
  case 0:
    $max = 3;
  case 1:
    $max = 7;
    break;
  case 2:
    $max = 4;
    break;
  case 3:
    $max = 8;
    break;
  case 4:
    $max = 14;
    break;
  case 5:
    $max = 3;
    break;
  }
  $form = ic_tool_steps($brain_state, $max);
  $form_info = array(
    'id' => 'instant_connection',
    'show back' => TRUE,
		'next text' => 'Continue',
		'finish text' => 'Close',
    'next callback' => 'ic_tool_next',
    'finish callback' => 'ic_tool_finish',
    'forms'=> $form,
  );
  $ic_tool = ic_tool_get_page_cache(NULL);
  $form_state = array(
    'ic cache' => NULL,
    'ic_obj' => $ic_tool,
    'commands' => array(),
    'title' => t('Instant Connection'),
  );

  if(!$ic_tool){
		$step = 0;
		$ic_tool = new stdClass();
		ctools_object_cache_set('ic_tool_basic', $form_state['ic cache'], $ic_tool);
	}
	// this is magic that makes it work
//    if ($js) {  
     ctools_include('ajax'); 
     ctools_include('plugins'); 
     drupal_add_js('misc/jquery.form.js'); 
     ctools_add_js('ajax-responder'); 
     $form_info['path'] = "instant-connection/ajax/$brain_state/%step"; 
     $form_state['ajax'] = TRUE; 
     $form_state['ajax render'] = 'ecourses_og_ic_ajax'; 
     $form_state['no_redirect'] = TRUE; 
     $form_state['rerender'] = TRUE; 
     $output = ctools_wizard_multistep_form($form_info, $step, $form_state);
     $form_state['commands'][] = ctools_ajax_command_replace('.ic-tool-ajax', $output);
//    }  
//  
//    else {  
//     $form_info['path'] = "instant-connection/nojs/$brain_state/%step"; 
//     $title = t('Instant Connection'); 
//     drupal_set_title($title); 
// 	  $output = ctools_wizard_multistep_form($form_info, $step, $form_state); 
//     return $output; 
//    }  
}

function ecourses_og_ic_ajax(&$form_state, $output) {
  ctools_include('ajax');
  ctools_include('plugins');
  ctools_add_js('ajax-responder');
  drupal_add_js('misc/jquery.form.js');
  $commands[] = ctools_ajax_command_replace('.ic-tool-ajax', $output);
  ctools_ajax_render($commands);
}

I have tried adding all the ctools_includes, ctools_ad_jses, etc everywhere (even within the form items themselves) and the result is the same. I have tried adding the code from Drupal.CTools.AJAX.ajaxSubmit = function (form, url) and processing it that way, but I guess I'm just an apprentice mage right now and nowhere near Merlin's greatness because that didn't work either. =/

So where am I going wrong? Why isn't ctool-use-ajax being processed?

Thanks in advance!

Comments

intrafusion’s picture

Subscribe

jludwig’s picture

Status: Active » Closed (fixed)

Hey intrafusion,

I found a solution a while back and forgot to post my updates here. Sorry! Anyway, change this:

  $commands[] = ctools_ajax_command_replace('.ic-tool-ajax', $output);
  ctools_ajax_render($commands);

to this:

  $commands[] = ctools_ajax_command_html('.ic-tool-ajax', $output);
  ctools_ajax_render($commands);

It seems like ctools_ajax_command_html() is the only command that works on forms like this. I'm pretty sure there were a few other changes I made to get it working, but I've forgotten now and this was the magic that ended up making it all work.