How to redirect confirmation page after submitting form in Laravel?

Chonchol Mahmud

I have a form.This action is:

<form action="{{url('career/save/{id}')}}" method="POST" enctype="multipart/form-data">

Route:

Route::group(['prefix' => 'career'], function () {
    Route::get('apply', ['as' => 'addApplicant', 'uses' => 'ApplicantController@create']);
    Route::post('save', ['as' => 'saveApplicant', 'uses' => 'ApplicantController@store']);
    Route::get('confirmation/{id}', ['as' => 'confirmationMsg', 'uses' => 'ApplicantController@show']);
});

Controller:

public function store(Request $request)
{
    $applicant = new Applicant();
    $applicant['name'] = $request->input('name');
    $applicant['sex'] = $request->input('sex');
    $applicant['marital_status'] = $request->input('marital_status');
    $applicant['date_of_birth'] = $request->input('date_of_birth');
    $applicant['email'] = $request->input('email');

    $applicant->save();
    \Session::flash('flash_message','Application has been successfully submitted.');
    return redirect(route('confirmationMsg'));
}
public function show($id)
{
    $applicantData = Applicant::whereId($id)->first();
    return view('applicant.confirmation',compact("applicantData"));
}

If every applicant/everyone submit this form then it will create an ID and redirect this in confirmation page with his submitted data.

But after submitted i have got:

../public/career/save/%7Bid%7D

I can manually type ../public/career/confirmation/14 and its work perfectly.Now i want after submitting form it will redirect this ../public/career/confirmation/ID. ID is dynamic.How can i do that? Thanks in advance.

Qazi

you can redirect after submission by doing this

return redirect()->to('career/confirmation/'.$id); //pass your dynamic id

or by doing this

return redirect()->route('confirmationMsg',['id'=>$id]); //pass your dynamic id

DO it like this, $id = $applicant->id;

replace your this line

return redirect(route('confirmationMsg')); with this one

return redirect()->route('confirmationMsg',['id'=>$id]); //pass your dynamic id

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Redirect to contacts page after submitting form in laravel 4

How to redirect after submitting form

How to redirect to another HTML page after submitting a form?

PHPMAILER, how to redirect to the thank you page after submitting the form?

redirect to another page after submitting a form

Form not submitting after bootstrap confirmation

How to redirect user after submitting form with React

How to redirect website after submitting google form?

How to redirect after submitting form in php

Blank Page After Submitting Form in Laravel

How can I redirect to a new page after submitting a form using Jinja template?

How to redirect to newly created document page after submitting the form firestore for web

How to redirect to List View Page in PHP CodeIgniter using parameters after submitting a form?

How to redirect to a new page using an object id after submitting a form in Django?

"redirect" function of django is not and after submitting the form, user remains on same page

How to redirect on submitting a form?

How to redirect page after saving the form to the database using Laravel?

How do I redirect users after successfully submitting form data?

How to prevent redirect after submitting data through a form

How to redirect to another page after submitting an alert in ASP MVC

How to redirect to another page with passing data after submitting form in using react-router-dom v6?

how to redirect page after sending javascript form

After submitting 'Contact' message, how do I get it to stay on page and generate a text confirmation?

How to get the sucess message in the same page after submitting the contact form?

How to get the success message in the same page after submitting the form?

Redirect to other view after submitting form

Trying to redirect in PHP after submitting an email form

Redirect to same page after successful submission of a form and clicking OK on a confirmation message

After submitting my React form, is there an easier way of passing an object to the page I want to redirect to?