We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Validate a form on multiple pages and save it on the last page

Hi all,

I'm struggling with something, maybe you know the solution!

I would like to have a form, which is divided in more pages. The user fills in his/her username / password on the first page, then clicks 'next' and fills in the next on page 2 and so on. On the last page, the user needs to get all the information filled in and at last save it to the database. No problem so far, i just store all the data in a session. And everytime i redirect to a new page i store new data in the session. At the last page I get all the data and show it, and save this data to the database.

But what if i want to validate this data each time for each page? If I build a validation function in my user model, it validates every field every time, but I just want it for some fields that are just on that page, and show their errors on that page...

Ofcourse I could build more functions in my model, so that every page has his own validation, but in the future i would use it for other elements, so that's not the best solution..

Do you know what to do?


Instead of validating in the model (which in your case would only happen in the last page) you can validate each form as it comes up.

Have a look at this



Thanks, that is a solution. But then i have 4 forms of the same model but in different parts? That's not ideal? I want to use one form and at every page use some fields of that form.

I thought maybe i can give my validation() funtion some parameters, and each time i 'post' something (clicking 'next' ) I get the data, validate it with a parameter of that page and if it is ok, set the data in the session..

In the validation i simply check the parameter, and do only the validation of that parameter and so that page.

Maybe that works?