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

NikolaiKaskatiiski's avatar

Nested forms

Hello, I am brand new in web development. I am trying to perform following scenario: Another scenario: Page 1 with form A, fill in some data. with button diffident than submit go from form A to a Page 2 with form B via Route (method get) we are in form B now. Do some input and go to Page 1. I need to keep user input on page 1 from A.

what is the proper way to do it?

0 likes
2 replies
furqanDev's avatar

You can save user input in a session and and instead of adding a submit button on page 1 you will add a next step button with "Get Request".

On page 2 you will have the button to submit or go to previous page.

In your first form you need to set value attribute of input to the session value because when user first land on the page there will be no information is you need to add a check for that. On page 1 pseudo code.

<input name="name" value="@if(isset(session['name'])) {{ session['name'] }}  @endif"/>
NikolaiKaskatiiski's avatar

OK thanks for the feedback, but still there is no light in the tunnel :) I will add more details and example I have usual MVC for user in addition I have MVC for a role (called Roles) I am playing with inertia js. Thus on the views for Create and Update of the user I have a button to navigate to select a roles for the user being created or updated. Thus button goes to mvc of roles and returns selected objects. So when I an back to users view the user input was lost. As snippets of code web.php Route::get('roles/selectARole', [RolesController::class, 'selectARole']) ->name('roles.selectARole') ->middleware(['auth', 'permission']);

Route::resource('roles', RolesController::class) ->middleware(['auth', 'permission']);

Route::put('users/assignRoleToUser', [UsersController::class, 'assignRoleToUser']) ->name('users.assignRoleToUser') ->middleware(['auth', 'permission']);

Route::resource('users', UsersController::class) ->middleware(['auth', 'permission']);

pages….Users\Create.vue addRole(){ this.$inertia.get(this.route('roles.selectARole'),{ 'mTitle': this.form?.first_name+' '+ this.form?.last_name, 'selectedRole': this.user?.role, 'returnHere': window.location.href, },{ preserveState: true})

pages… Roles\SelecARole.vue submit() { var data = new FormData(); data.append("selected_role", this.form.role || ""); data.append('return_url', this.form.url || null), data.append("_method", "put"); this.$inertia.post(this.route("users.assignRoleToUser"), data, { onStart: () => (this.sending = true), onFinish: () => (this.sending = false), });

},

and then in controller

public function assignRoleToUser() { Request::validate([ 'selected_role' => ['required', 'exists:roles,id'], 'return_url' => ['required', 'nullable'], //to add proper validation ]); $role = Role::where(['id'=> Request::get('selected_role')])->first(); return redirect(Request::get('return_url'))->with('role', $role)->with('success', 'Role Selected'); }

So I can grab the session in the addRole callback and use it in assignRoleToUser, but looks very unsecured to me as no idea how to set proper validation So please enlighten me :)

Please or to participate in this conversation.