You can achieve this by storing data either into a session variable array or temp database table. I would prefer to store it in session.
If you are doing it using session then it can be:
When user clicks on submit, do you check that the user is logged in or not? If yes, then store data into a table. If not, then store it into a session array, say xyz[]
. After storing it, redirect the user to a login page. After login, you can check if the session array xyz[]
contains any value. If it does, store it into a particular table and don't forget to unset session array xyz[]
. Otherwise, redirect user to home.
If you are doing it using the DB then it can be:
When user clicks on submit, do you check that the user is logged in or not? If yes, then store data into db table. If not, then store it into a temporary db table. After storing it, redirect user to login page. After login, you can check if the temp db table contains any record. If it does, then move it into a particular table and don't forget to delete record from the temp db table. Otherwise, redirect user to home.
or else best way
In starting of your form just check if user logged in or not? if not then redirect him to login page. Otherwise, allow them to fill data in form.