Input/Output
Laravel Input/Output

Create Form
In Laravel there are two way to retrieve input value.

By Input method
By Request instance properties

Now we create form and display these value. For this purpose we create

1- User Input Form and save in View folder
for example - resources->view->userform.blade.php

2- Create Controller and save in Controller folder
for example - app->Http->Controllers->Usercontroller.php

3- Create routes and save in routes->web.php

Create Route

<?php
Route::get('inputform','InsertValue@inputform');
Route::post('printform','InsertValue@printform');

User input form

<html>
<head>
<title>User Input Form</title>
</head>
<body>
<form name="frm" action="printform" method="post">
<input type = "hidden" name = "_token" value = "<?php echo csrf_token() ?>">
<table>
<tr>
<td>Name</td>
<td><input type = "text" name = "name" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type = "text" name = "email" /></td>
</tr>
<tr>
<td colspan = "2" align = "center">
<input type = "submit" value = "Submit" />
</td>
</tr>
</table>
</form>
</body>
</html>

Controller

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;


class InsertValue extends Controller {
public function inputform(){
return view('user_form');
}

public function printform(Request $request){

//By Input Method
echo $request->input('name');
echo "<br>";
echo $request->input('email');
// By Properties
echo "<br>";
echo $request->name;
echo "<br>";
echo $request->email;

}
}


Previous
Next