smohadjer / formwizard

A boilerplate for multi-step single-page forms
MIT License
1 stars 0 forks source link

Get next step from form data #25

Open smohadjer opened 6 years ago

smohadjer commented 6 years ago

I don't like this line:

$nextStep = 'form.php?step=' . ($step + 1);

Imagine you have a form with ten steps and then you want to add a step between 2nd and 3rd. The easiest way would be to call it step 2.5, otherwise if you want to call it step 3 it means you have to rename all existing steps and form action inside them and other things that depend on step number, incrementing them all by one. Lots of work with possibility of breaking things. Why don't we simply get the next step a form should direct to from a hidden field inside that step? Wouldn't it make steps more modular and changes easier?

<input type="hidden" name="nextstep" value="3" />

smohadjer commented 6 years ago

If you agree, let me know and I will make the change.

smohadjer commented 6 years ago

I went ahead and made the change in a new branch here: https://github.com/smohadjer/formwizard/commit/0361e68f1f665f7bbd80f338ebee2f5c21042dc3

I think this can also help us with implementing sub-steps. However we still need to fix the code for navigation to support this. I suggest that instead of a "TOTAL_STEPS" variable we use an array like this:

STEPS = [1, 2, 2.5, 3, 4];

Then we can loop through this array to generate markup for navigation links. Do you agree?

smohadjer commented 6 years ago

I implemented that and opened a pull request for you. https://github.com/smohadjer/formwizard/pull/26