0

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.

7
  • You are missing the csrf token , try adding @csrf to both forms. Commented Jul 11, 2019 at 9:49
  • Which kind of error message is shown? Commented Jul 11, 2019 at 10:03
  • Hi, @Remul thanks for the help, I will check. Commented Jul 11, 2019 at 10:12
  • Hi @Nico Hasse thanks for the help, it shows the following error, Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message Commented Jul 11, 2019 at 10:13
  • Hi @Remul thanks for the help, you give me the right answer. Commented Jul 11, 2019 at 10:38

2 Answers 2

4

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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

8 Comments

Hi @Julius Fasema, Thanks for the help.
uwc. if you fine it helpful, you have to vote the answer
Hi @Julius Fasema, I voted it but it shows the message, Thanks for the feedback! Votes cast by those with less than 15 reputations are recorded but do not change the publicly displayed post score. My reputations are only 11.
its ok! it for sake of other users so that they would know that the answer is helpful and they can make use of it.
Ya it's true. It is useful for others as like me. :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.