multi page frorms and api backend

Published 1 year ago by psyopus

Im doing a new project and i want the separate front and backend completely so theoretically anyone can build his own frontend by interacting with the api backend or even just machine to machine interaction.

this is fine for single requests but since an api is stateless but i was wondering how to handle data that has to be cut up in steps.

For example a really long form that spans several pages/ chapters.

With just old school php application you'd simply store the data from each page into session and after filling out all of the single pages successfully you'd store the entire session into the database.

But this is going to be a problem when working with api request because it doesnt use sessions.. its stateless.

Sure you could just save all data in session anyway on the frontend and then post the entire session to the api endpoint but what if the api returns a validation error for some reason because it got a stricter validation rule for a form-field that was already validated on page 1 on the frontend?

from the user point of view it would be very strange if at that point, after supposedly everything was correctly filled out the page still gets redirected back to the first page with a message that suddenly something was not filled out correctly after all.

i guess the problem at hand is clear so my question is, how to handle/ setup something like this.

Are there common practices to solve this? Or perhaps it's just a really bad idea to even want to go this way?

what are your thoughts?

Ruffles
Ruffles
1 year ago (297,250 XP)

You could store the data partially in the database and have a completed field which unless it is 100, you won't show that record anywhere.

psyopus
psyopus
1 year ago (10,305 XP)

but how would i track that data in the api? pass a custom temp id or something?

i mean, i would find it hard to believe it this hasnt been done before by someone else..

kalpesh12

Yes, I also faced similar issues when using API. We were trying to use API of xe but could not do so for https://www.revivedissertation.sg/ . Later we manually configured the foreign price functionality.

Ruffles
Ruffles
1 year ago (297,250 XP)

You would probably have a unique field (for example name) and based on that field, you could check if it exists, update it, else create a new record.

Please sign in or create an account to participate in this conversation.