Request Data Retrirval
Request Data Retrirval
Request Data Retrirval
• Route::get('/form', [RequestDemoController::class,
'showForm']);
• Route::post('/process',
[RequestDemoController::class, 'processForm']);
• Create a Blade view file named form.blade.php in the resources/views directory to display the form:
• <!DOCTYPE html>
• <html>
• <head>
• <title>Request Data Retrieval Demo</title>
• </head>
• <body>
• <h2>User Information Form</h2>
• <form method="post" action="/process">
•
•
@csrf
<label for="name">Name:</label>
Create the Form View:
• <input type="text" name="name" id="name"><br><br>
•
• <label for="email">Email:</label>
• <input type="email" name="email" id="email"><br><br>
•
• <input type="submit" value="Submit">
• </form>
• </body>
• </html>
Create the Controller Methods:
public function showForm()
{
return view('form');
}
<!DOCTYPE html>
<html>
<head>
<title>Request Data Retrieval Demo - Confirmation</title>
</head>
<body>
<h2>Confirmation</h2>
<p>Name: {{ $name }}</p>
<p>Email: {{ $email }}</p>
<hr>
<h3>All Input Data:</h3>
<pre>{{ print_r($allData, true) }}</pre>
</body>
</html>
Old Input
Old input refers to the ability to retrieve and
display previously submitted form data, often
used in forms that need to be redisplayed with
user-submitted data after a validation error
occurs.
Laravel provides a convenient way to access old
input data using the old() function.
Let’s make a new controller for this.
<label for="email">Email:</label>
<input type="email" name="email" id="email" value="{{ old('email') }}"><br><br>
<label for="password">Password:</label>
<input type="password" name="password" id="password"><br><br>
// Registration logic (not saving to the database in this example) would go here
// ...
use Illuminate\Support\Facades\Validator;
Now, let’s define routes to access our pages in
web.php
Route::get('/register', [RegistrationController::class,
'showRegistrationForm’]);
Route::post('/register', [RegistrationController::class,
'processRegistration']);
Always remember to include the controller
before using it.
use App\Http\Controllers\RegistrationController;