简体   繁体   中英

How to pass data from one form to another form on a different page in laravel 5.7?

I want to pass an email value in a textbox from welcome page to register page in Laravel without using the database. I tried the following code in simple PHP page it works fine but when I use in Laravel 5.7 page it shows an error.

Welcome page

<form method="POST" action="register">
  <input type="text" size="40" name="email">
  <input type="submit" name="submit">
</form>

Register Page

<form method="POST" action="register">
  <input type="email" size="40" name="reg_email" value="<?php echo $_POST['email']; ?>">

  <input type="submit" name="submit">
</form>

I want that when I write an email in welcome page form textbox & submit, it shows or display in a register page form email textbox without using Database.

You could send the email as a query string parameter to the registration page.

<!-- Welcome Page (Note the GET method) -->
<form method="GET" action="/register">
    <input type="text" size="40" name="email">
    <input type="submit" name="submit">
</form>

Make sure you're including the csrf token in your request.

<!-- Registration Page -->
<form method="POST" action="/register">
    @csrf
    <input type="email" size="40" name="reg_email" value="{{ request('email') }}">
    <input type="submit" name="submit">
</form>

try this:

'''' Welcome page: where user would enter the email before proceeding to registration page

<form method="POST" action="{{ route('welcome') }}">
  {{ csrf_field() }}
  <input type="text" size="40" name="email">
  <input type="submit" name="submit">
</form>


'''' Register Page: this is where the email displays inside the input name reg_email 

<form method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
  <input type="email" size="40" name="reg_email" value="{{ $myemail }}">

  <input type="submit" name="submit">
</form>

 //the controller collects the email input from the welcome page
public function Welcome(Request $request)
{
  $email = $request->input('email');
  $data['myemail']=$email; //assign the email variable myemail data to be pass to registration page view
  return view('registerpage',$data);  //pass the data to the view

}

//Route
Route('/welcome-page','MyController@Welcome')->name('welcome'); //ofcourse the route using name route welcome

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