简体   繁体   中英

Laravel form no data submitted

My form in my-profile.blade.php looks like this:

<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:

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

MyProfileController controller:

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. 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'));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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