saving old input values without submitting in Laravel

Viewed 243

I'm working with Laravel.

Is there a way to save old input for a form, without submitting it, so that when we redirect back, we don't lose the old input, and we continue from where we left?

I know about the withInput function in laravel , but in order for it to work, you should submit, and I don't wanna submit.

I was thinking maybe I could save inputs in session, but I don't know how or even if it's a good idea.

1 Answers

Well, if you want it to save permanently, you should ajax on input event, and save it to database. But if you just wanna to keep value on page reload or redirect, it's ok to use cookies.

<script src="https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js"></script>
  
<input oninput="Cookies.set('oldValue', this.value)" value="{{$_COOKIE['oldValue']}}">

There is Cookie::get method in laravel, but you might encounter encryption problems while reading from js

Related