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:

$form_state['step'] = $form_state['next'];

I've tried as well to define foo_form1_submit() with following code:

$form_state['next'] = 'step-3';

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

Comments

kenorb’s picture

Issue summary: View changes

improved sentence

kenorb’s picture

Status: Active » Fixed

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

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.

merlinofchaos’s picture

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.

kenorb’s picture

Thank you, I'll have a look.

merlinofchaos’s picture

Title: How to skip one step in wizard programatically? » Documentation: How to skip one step in wizard programatically?
Component: Miscellaneous » Documentation
Category: support » 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.

Status: Fixed » Closed (fixed)

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

kenorb’s picture

Status: Closed (fixed) » Postponed
merlinofchaos’s picture

Status: Postponed » Active

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

kristiaanvandeneynde’s picture

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

Example code that worked for me:

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'];
}
jbiechele’s picture

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?

merlinofchaos’s picture

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

Can you be certain your code is actually executing?

merlinofchaos’s picture

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.

merlinofchaos’s picture

Issue summary: View changes

added dash

kenorb’s picture

Priority: Normal » Minor
Issue summary: View changes
japerry’s picture

Status: Active » Closed (outdated)

Drupal 7 is no longer supported, closing.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.