简体   繁体   English

Laravel表格未提交数据

[英]Laravel form no data submitted

My form in my-profile.blade.php looks like this: 我在my-profile.blade.php中的表单如下所示:

<form id="profile-form" role="form" method="POST" action="{{ route('myprofile.store') }}">
      <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
      <div class="col-md-6">
          <label for="first_name">First Name</label>
          <input type="text" class="form-control" id="first_name" placeholder="First Name" value="{{$currentUser->first_name}}" required>
      </div>
...
      <button type="submit" class="btn btn-primary">Save</button>
</form>

web.php file: web.php文件:

Route::resource('myprofile', 'MyProfileController');

MyProfileController controller: MyProfileController控制器:

public function store(Request $request)
{
        Log::info("request:");
        Log::info($request);
        Log::info("input:");
        Log::info(Input::all());
}

After logging the request and input: 记录请求并输入后:

local.INFO: request:  
[local.INFO: array (
  '_token' => 'S0u7OzktqMS5zVLr9WHwIq52EhGfZKoQWRD6XlCR',
)  
local.INFO: input:  
local.INFO: array (
  '_token' => 'S0u7OzktqMS5zVLr9WHwIq52EhGfZKoQWRD6XlCR',
)  

This is what I get. 这就是我得到的。 I also tried the {{csrf_token()}}, the output is the same. 我还尝试了{{csrf_token()}},输出是相同的。 The controller's store function runs, so the action is set up okay. 控制器的存储功能将运行,因此可以将操作设置为正常。 What could be the problem? 可能是什么问题呢?

我认为您的输入中没有名称属性。

Try this: 尝试这个:

<form id="profile-form" role="form" method="POST" action="{{ route('myprofile.store') }}">
      {{csrf_field() }}
      <div class="col-md-6">
          <label for="first_name">First Name</label>
          <input type="text" class="form-control" id="first_name" name="first_name" placeholder="First Name" value="{{$currentUser->first_name}}" required>
      </div>

      <button type="submit" class="btn btn-primary">Save</button>
</form>

Controller: 控制器:

public function store(Request $request)
{
     dd($request->get('first_name'));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM