mezie's avatar
Level 8

Submit form data after a redirect to login

Having this scenario where not logged users can fill a form submit it but redirected to login/register, then after login/register the form previously filled will be submitted.

Also, the user ID has to be submitted with along with the form data, hence the need to login/register.

What I am currently doing is, persist the form data to local storage, then when the user login, I get the form data saved to local storage and perform an AJAX request with. The problem with this approach is that upon successful login there is a redirection which hinders the AJAX request from firing.

0 likes
4 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

Of course, not the best practice. However, can recommend you to use session.

May be the procedure will be-

  • Generate a unique id to track the visitor and store in session
  • Store every form element data in session separately based on unique id whatever visitor wrote
  • Finally, if user signup and still has value in unique id session, get all the session values and insert into database based on signup id.

Ref: https://laravel.com/docs/5.4/session

2 likes
mezie's avatar
Level 8

@tisuchi Also tried using session encountered some issues (which I can't remember now) with it too though I didn't generate unique ID for each visitors

1 like
mezie's avatar
Level 8

Thanks for the link, will try them out.

1 like

Please or to participate in this conversation.