We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to create a step by step form

I'm currently working on a project that has pages with complex forms and a lot of inputs, to break it down nicely I'm dividing the forms into a step-by-step process.

How would one validate the form on each step before going to the next step and then save the whole form on the final step?

I can't seem to find anything documented about this sort of process as it likes to validate the form in it's entirety if I use the form builder.

Just an idea ...

what about creating a form for every step, validate it, and if it is ok, serialize the data and put it in the session-bag?!



33.8k

To AljoschaPeters:

And why just not use AJAX in every step instead of making that number of forms? (And yeah, put it in the session bag)

In that way, he only would need a one function whose data for $.ajax will be setted with a switch(var), where var is the step number. Then, you pass that var to the action, and it will return a response according to it's value. This way you not have to do many forms that points to the same action (only one JS function), and also it wouldn't reload the entire page.

(PD: the reply button doesn't work)

edited Aug '14

To David:

It was just a short idea. Thought, that answer is short and clear. My head is busy with my work ;)

But I also worry about users that have no javascript enabled and about users that require screenreaders. (take a look at: https://webaim.org/techniques/ajax/ ). I have not take a closer look at AJAX and Accessability, but I will.

If he wants to use AJAX ok, if not, ok. :)

Best wishes



33.8k
edited Aug '14

Didn't know that about the third paragraph.

Then I think it's the only best option. That, or do one form that in the action has different code for every button sent.