Neither ctools_build_form nor ctools_rebuild_form will work with #ahah callbacks in ctools wizard forms. This is partly because ctools_build_form ignores a $_POST['form_build_id'] even if one is set when it tries to rebuild the form and partly because ctools_rebuild_form does not support wrapper callbacks.

This patch resolves this issue making ahah rebuilds of ctools wizard forms quite easy (just setup the ctools data in form_state for your ctools wizard form and call ctools_build_form and return the json).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tizzo’s picture

Status: Active » Needs review
FileSize
2.12 KB

This patch should apply to both the 6.x version and HEAD.

kleinmp’s picture

I've tested out this patch with an 'Add Another' button on a multipage ctools form, and it's working well. The extra documentation makes things much easier, so that one doesn't have to delve too deeply into the code in order to figure out what values need to be passed in the form state.

Thumps up!

afreeman’s picture

+1 I've run into problems with this myself, thanks for posting a patch!

merlinofchaos’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev

I missed this since it was posted against 7.x

merlinofchaos’s picture

   if (!empty($form_state['rebuild']) || !empty($form_state['storage'])) {
-    $form = ctools_rebuild_form($form_id, $form_state, $args);
+    $form = ctools_rebuild_form($form_id, $form_state, $args, $_POST['form_build_id']);
   }

I don't think on the rebuild we should be fetching the form build id out of $_POST. (IN fact, there's a couple of existing references to $_POST that I'm dubious about as well). We probably shouldn't be fetching from $_POST directly but from $form_state['input'].

But also, if there is a build ID, at this point, it should already be set in $form_build_id -- and we should use that, shouldn't we?

It's not clear to me why the form_build_id is being added to this call. It's not there in core. Can you explain to me why we need it?

merlinofchaos’s picture

Status: Needs review » Needs work
tizzo’s picture

Status: Needs work » Needs review
FileSize
2.66 KB

Ooooooh... Ok, so sorry about messing up the version number.

Actually in the event of an ahah callback $form_build_id never gets set, so that's why I was pulling it directly from $_POST. I moved that up above where it was already used cleaning that up just a bit. I think that might be the only place we can reliably find form_build_id in an ahah callback at that stage.

Rerolled patch attached.

merlinofchaos’s picture

Status: Needs review » Fixed

Committed, with a slight change to eliminate references to $_POST which are actually wrong anyhow.

Status: Fixed » Closed (fixed)

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

memyselfandm’s picture

@tizzo @merlin, can one of you expand upon this particular section:

// If this function is being used to perform an '#ahah' callback
// to rebuild some or all of a ctools wizard form step, be sure that
// $form_state['wrapper callback'], $form_state['form_info'],
// $form_state['step'], $form_state['no_redirect'], and $form_state['rebuild']
// are properly set.

I'm having trouble using this code, and I've created a separate issue with the specifics here: #1065172: '#ahah' not working in Panels content type settings modal

Thanks a lot,
M.