I am using the ctools wizard component and these are 2 "issues" i have ran into. I found some workarounds and thought it would be helpful to include them in the advanced help :

1 - Back button and validation

Some brieg information is included on advanced help but you might want to include a workaround :
To avoid having drupal trying to Validate a form when the user clicks the back button, include the following at the top of you form validation function :

if ($form_state['clicked_button']['#wizard type'] == 'cancel') {
    // Clear the error messages.
    drupal_get_messages('error');
    // Clear the form error state (the required fileds errors).
    form_set_error(NULL, '', true);
    return TRUE;
}

2 - Wizard for anonymous users

If you are creating a wizard that would be used by anonymous users, you might run it to some issues with page caching for anonymous users. You can circumvent this issue by using hook_init and telling drupal to never cache your wizard pages :

function mymodule_init() {
  // if the path leads to the wizard
  if (drupal_match_path($_GET['q'],'path/to/my/wizard/*')) {
    // set cache to false
    $GLOBALS['conf']['cache'] = FALSE;
  }
}
CommentFileSizeAuthor
#3 ctools-help-wizard.patch1.63 KBredben
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ayalon’s picture

Hey renben!

Thanks for this post. I was googling for exactly this bug fixes. I think everyone coding a wizard using ctools will come accross these problems and your post is very helpful an clear!

merlinofchaos’s picture

It would facilitate adoption of this if you could provide a patch to the advanced help file. =)

redben’s picture

FileSize
1.63 KB

Sorry :) here is a patch
BTW i changed the code example for validation to handle anything that's not what should be next :

  // if the clicked button is anything but the normal flow
  if ($form_state['clicked_button']['#next'] != $form_state['next']) {
    drupal_get_messages('error');
    form_set_error(NULL, '', TRUE);
    return;
  }
redben’s picture

Status: Active » Needs review
merlinofchaos’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Needs review » Patch (to be ported)

Committed to D6. Thanks for the patch!

merlinofchaos’s picture

Status: Patch (to be ported) » Closed (duplicate)

All of the 'to be ported' patches got merged in during the porting sprint in September.