Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ImWaller's avatar

Share data to the next page and remember the form data

I create a project for meals plan with laravel, inertiajs, vue. I have a form and a button to preview the form data to new page. How to keep the form data to share to the next page and display them?

0 likes
6 replies
MohamedTammam's avatar

Use session to store the data that's submitted and send it the next page.

MohamedTammam's avatar

@ImWaller When submitting

session()->put('foo', 'bar');

In the next page

$foo = '';
if(session()->has('foo')) {
	$foo = session()->get('foo');
	session()->forget('foo');
}

return Inertia::render([ 'foo' => $foo ]);
ImWaller's avatar

@MohamedTammam thanks for the replies but I need to share the data between Vue pages component and session doesn't work for me. One solution I have in mind is to store the form data to localstorage and share to the next page and if user go back and submit, clean the localstorage form data. Are there any way to share the data with the inertiajs or the Vue to the next gape. Another solution is to use the inertia.visite with get or post method, pass the data and get the data when the preview page load but I'm not sure if it is working this. I will try and I reply soon.

MohamedTammam's avatar

@ImWaller I don't know why the session doesn't work. However, as you said you can store the data in LocalStorage, state management, higher order component etc. and then display it in the next page.

ImWaller's avatar

@MohamedTammam doesn't work because the data are not from backend but from frontend. I need to share data between pages/components but not from laravel to a component.

Please or to participate in this conversation.