Detecting current page of a multi page form

By: Rich Stern | Asked: 02/15/2023
ForumsCategory: General questionsDetecting current page of a multi page form
Rich Stern asked 2 years ago

I've built a multi-page form, and as part of the "Before HTML" settings, I have a shortcode which injects a breadcrumb at the top of the form, showing the input history.  The breadcrumb function examines the form fields POST values to determine what the user has entered, in order to construct the breadcrumb.

This works fine as long as the user goes forward.  But if they go backwards and change answers on the form, there can still be POST values from previously entered fields on later pages, and the breadcrumb doesn't display correctly.

I'm struggling to find a way to detect what form page the user is on, so I can add logic to the breadcrumb function, so it won't display any info beyond the user's current page.

Looking for suggestions.  Thanks in advance!

1 Answers
Victor Font answered 2 years ago

The only thing I can see in a multi-page form to indicate page number is after you click off of page 1 the first time, a new query string parameter for the page you're on is added to the URL. The only time there's no page parameter in the query string is when the page first loads. You can use JavaScript to read the query string parameter.

Rich Stern replied 2 years ago

Victor, thanks for the reply.

Because of the conditional page logic and the ability of the user to back up and go down a different logic branch, what I needed to do was clear the hidden field values on later pages using jQuery, if an earlier field had a change event that invalidated the input on a different conditional branch. That allowed my shortcode for the breadcrumb to reliably output the logical, current state of the user's selections.

A (simplified) example: If page one was a dropdown of "Food Group" and choices were Dairy, Fruit, Meat, Vegetables, and a user chose "Fruit," and then "Apples" from a dropdown on the second page, but then backed up to the previous page and changed the first selection to "Dairy", I cleared the hidden "Fruit" value via jQuery, so it won't show up in the breadcrumb generated by my shortcode.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right