How to skip step 1 on multi-step/wizard webform?

I need to skip step 1 and start on step 2 of a multi-step/wizard webform when a certain condition is true.

I found documentation regarding this, How to programmatically skip steps in wizard forms

The key part being in hook_form_alter putting

$form_state->set('current_step', $all_keys[$goto_destination_step_index-1]);

What this does is fool drupal into thinking you’re currently in the previous step that you want to go to, when in reality you’re not. But the problem with this solution, is that it only works when you click the “next step” button and not on page load. Thus, the above solution only works for all but the first step.

I have tried doing

$form['progress']['#current_step'] = 'step_2';

But all this does change the progress marker to step 2, but I still see step 1’s form.

I need to find a way to fool Drupal into thinking that I have completed step 1.

I tried doing $form_state->set('form_field' $value); when I looked at form_state->getValues(); they were not set. I so I set them with $form_state->getValues()['form_field'] = $value; on all step 1 fields, but doing this alone does not trick Drupal.

There must be somewhere were Drupal stores that step 1 has been completed, but haven’t been able to figure out where. My guess would be somewhere on $form_state, but I have not found it yet.

Update:

I don’t really need the answer to this anymore, as the condition is no longer needed so it was decided to remove the question’s step 1 altogether. But if you happen to know the answer, feel free.

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

How to skip step 1 on multi-step/wizard webform?

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.