Download & Extend

Documentation: How to skip one step in wizard programatically?

Project:Chaos tool suite (ctools)
Version:7.x-1.x-dev
Component:Documentation
Category:task
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

I've the form defined in ctools with i.e.:
- step-1 as foo_form1()
- step-2 as foo_form2()
- step-3 as foo_form3()

On step-1 page user choose Yes or No. Depending on answer, if the answer is No - I want to skip step-2.

I've tried following solutions by now:
In foo_form2() I did:

<?php
$form_state
['step'] = $form_state['next'];
?>

I've tried as well to define foo_form1_submit() with following code:
<?php
$form_state
['next'] = 'step-3';
?>

Not much difference.
Any ideas how to achieve that?
Thanks.

Comments

#1

Status:active» fixed

I've fixed by following code in my foo_form_info():

<?php
function foo_form_info() {
$form_info = array(
...
'order' => array(
 
'step-1' => t('Foo 1'),
 
'step-2' => t('Foo 2'),
 
'step-3' => t('Foo 3'),
...
);
$node = ctools_object_cache_get('foo', 'node'); // my cached node
$Node = entity_metadata_wrapper('node', $node);
if (!
$Node->field_yes_no->value()) {
  unset(
$form_info['order']['step-2']);
}
}
?>

It works!:)

Please re-open if there is any other easier solution.

#2

That is one of two possible solutions.

the other solution is that in formxxx_submit you can set $form_state['triggering_element']['#next'] = 'step' I think.
It might be $form_state['next'], I can't remember exactly now.

This is something that should be in the wizard documentation if it's not already; manipulating the flow programmatically is a key feature.

#3

Thank you, I'll have a look.

#4

Title:How to skip one step in wizard programatically?» Documentation: How to skip one step in wizard programatically?
Component:Miscellaneous» Documentation
Category:support request» task

In fact, I'm going to re-open this as a documentation issue. This absolutely deserves a section in help/wizard.html discussing how to control the flow.

#5

Status:fixed» closed (fixed)

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

#6

Status:closed (fixed)» postponed

#7

Status:postponed» active

Hm. This should be active, not closed or postponed.

#8

Based on line #432 in includes/wizard.inc, the value to change is $form_state['clicked_button']['#next']

Example code that worked for me:

<?php
function my_wiz_step1_submit($form, &$form_state) {
 
// next_screen is a #type => 'radios' element with wizard forms as options.
 
$form_state['clicked_button']['#next'] = $form_state['values']['next_screen'];
}
?>

#9

The solution in #8 from kristiaanvandeneynde works fine for the "Next" button. I assumed that this solution should also apply to "Back", but this is not so, or I'm doing something wrong.

For the "Back" button to skip a step I have to specify an explicit $form_state['redirect'] = 'my_redirect_path' in function celer_solicitud_wizard_next() to get this working.

Any idea why setting $form_state['clicked_button']['#next'] = 'step-something' does not work in the case of clicking the "Back" button?

#10

Hm. It should work; that button also uses #next to determine where to go.

Can you be certain your code is actually executing?

#11

In fact, that seems like a likely issue, because a _submit hook won't be called when 'back' is clicked. You could use a _validate callback instead, I think.