Hello! We're looking for more guidance on how to link directly into an intermediate page of a multi-step form. For context, what we're trying to do is use query parameters to indicate the values of elements in the early pages of the form (which is fine, not having problems with setting values) and then jumping to page 2 or 3 with those values pre-filled.
We have tried reading the value of current_page
from a query parameter, setting that on form state, and submitting and rebuilding the form (basically the steps in WebformSubmissionForm::wizardSubmit
). We've tried using states on earlier wizard pages that respond to becoming hidden based on values in query parameters to hide the initial pages on load, which also doesn't work (though using values on elements in earlier pages to skip intermediate pages through use of states does work fine and we are doing that).
We've also tried unsetting the pages we want to skip in $form['pages']
, setting $form['#attributes']['data-webform-wizard-current-page']
to our desired destination, and altering all attributes of the pages we want to skip in the ways they appear to be on a "valid" intermediate submission (code snippet follows).
Populating fields from query parameters is enabled and wizard page tracking is also enabled.
If you have any further guidance on where to look to try and make this happen, we'd appreciate it. We're very happy to write custom code to make it happen. We've tried a few avenues and we're not having luck thus far.
Basically, we're trying to understand how the form makes the decision to render an intermediate wizard page, and replicate that programmatically so that it can be done on first load.
We've attempted calling this from several steps. It's kind of a jumble of different techniques, but represents some of what we've tried.
function pin_help_webforms_help_center_contact_preload_page(array &$form, FormStateInterface $form_state) {
$submission_form = $form_state->getFormObject();
$pages = $form_state->get('pages');
// Set the page we want to be current page.
$destination = 'about_you_page';
$form_state->set('current_page', $destination);
$form['#attributes']['data-webform-wizard-current-page'] = $destination;
// Remove the first 2 pages from array.
unset($pages['overview_page_1']);
unset($pages['overview_page_2']);
$elements["overview_page_1"]["#access"] = FALSE;
$elements["overview_page_2"]["#access"] = FALSE;
$form_state->set('pages', $pages);
$form['pages'] = $pages;
// Set next link to for page after about you page.
$form["actions"]["wizard_next"]["#attributes"]["data-webform-wizard-page"] = 'the_problem_page_1';
// Try setting the first 2 steps as completed.
$formStateCompleted = $form_state->get('complete_form');
$formStateCompleted["elements"]["overview_page_1"]["#access"] = FALSE;
$formStateCompleted["elements"]["overview_page_1"]["#defaults_loaded"] = TRUE;
$formStateCompleted["elements"]["overview_page_1"]["#processed"] = TRUE;
$formStateCompleted["elements"]["overview_page_1"]["#after_build_done"] = TRUE;
$formStateCompleted["elements"]["overview_page_1"]["#validated"] = TRUE;
$formStateCompleted["elements"]["overview_page_2"]["#access"] = FALSE;
$formStateCompleted["elements"]["overview_page_2"]["#defaults_loaded"] = TRUE;
$formStateCompleted["elements"]["overview_page_2"]["#processed"] = TRUE;
$formStateCompleted["elements"]["overview_page_2"]["#after_build_done"] = TRUE;
$formStateCompleted["elements"]["overview_page_2"]["#validated"] = TRUE;
$form_state->set('complete_form', $formStateCompleted);
// Try submitting form and rebuilding state.
$submission_form->submitForm($form, $form_state);
$form_state->setRebuild();
}
Any advice much appreciated. Thank you~