我想在文本框中从欢迎页面传递电子邮件值,以在Laravel中注册页面,而无需使用数据库。我在简单的PHP页面中尝试了以下代码,但效果很好,但是在Laravel 5.7页面中使用时,显示了错误。
欢迎页面
<form method="POST" action="register">
<input type="text" size="40" name="email">
<input type="submit" name="submit">
</form>
注册页面
<form method="POST" action="register">
<input type="email" size="40" name="reg_email" value="<?php echo $_POST['email']; ?>">
<input type="submit" name="submit">
</form>
我希望当我在欢迎页面形式的文本框中编写电子邮件并提交时,它不使用数据库而在注册页面形式的电子邮件文本框中显示或显示。
答案 0 :(得分:2)
您可以将电子邮件作为查询字符串参数发送到注册页面。
<!-- Welcome Page (Note the GET method) -->
<form method="GET" action="/register">
<input type="text" size="40" name="email">
<input type="submit" name="submit">
</form>
确保在请求中包含csrf令牌。
<!-- 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>
答案 1 :(得分:1)
尝试一下:
'''' 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