Kolling Master
Kolling Master

Reputation: 85

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?

Upvotes: 1

Views: 1869

Answers (2)

Andr&#233;
Andr&#233;

Reputation: 51

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

Upvotes: 1

cssBlaster21895
cssBlaster21895

Reputation: 3710

I think there's no name attribute inside your input.

Upvotes: 4

Related Questions