简体   繁体   中英

How can I send a user defined data from one page to another in Laravel 7

PS -I am not going to use Session Flash as answered by someone in a similar question here .

I have a page which lets a user select if s/he has selected Value 1 or Value 2. Based on that, the user will be sent to another page, which will be sent to another page.

Here is my blade

Page 1

<select id="type" name="type">
  <option value="1">Value 1</option>
  <option value="2">Value 2</option>
</select>
<a href="{{url('page2')}}">Click Here</a>

Page 2

You have selected {{$type}}  <-------- Value 1/Value 2

But, I am not sure how to get the data in page 2.

Use a simple HTML form.

<form method="POST" action="{{ url('page2') }}">
    <select id="type" name="type">
        <option value="1">Value 1</option>
        <option value="2">Value 2</option>
    </select>
</form>

So then, on page 2 you can do {{ $type }} only if you have a controller like:

public function show(Request $request) {
    return view('name_of_view_for_page_2', ['type' => $request->input('type')]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM