お世話になっております。
PHPのLaravelでフォーム画面を作成しました。
http://localhost:8888/laravelapp/public/hello
しかし、フォーム画面のボタンを押しても、表示画面が変わりません(反応しない)。
誰かおしえていただけないでしょうか。
よろしくお願いいたします。
■したいこと
入力欄に文字(ex.山田)を入れて送信ボタンを押すと、こんにちは、山田さんが表示。
■上手くいかないこと
入力欄に文字を入れても、画面が変わらない。エラーにもならない。
■コード内容
resources\views\hello\index.blade.php
<html> <head> <title>Hello/Index</title> <style> body{ font-size: 16pt; color: #999; } h1{ font-size: 100pt; text-align: right; color: #f6f6f6; margin: -50px 0px -100px 0px; } </style> </head> <body> <h1>Blade/Index</h1> <p>{{$msg}}</p> <form method="post" action="hello"> {{csrf_field()}} <input type="text" name="msg"> <input type="submit"> </form> </body> </html>
app\Http\Controllers\HelloController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class HelloController extends Controller{ public function index(){ $data=['msg'=>'お名前を入力してください。',]; return view('hello.index', $data); } public function post(Request $request){ $msg = $request -> msg; $data=['msg'=>'こんにちは、'.$msg.'さん',]; return view('hello.index', $data); } }
routes\web.php
<?php /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { return view('welcome'); }); Route::get('hello','HelloController@index'); Route::post('hello','HelloController@index');
以上
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/01 03:52