简体   繁体   中英

laravel POST input not working

I'm really not sure why my controller is not receiving the attribute and value input! Here's my system.

View

<form method="POST" action="create/attribute">
    {{ csrf_field() }}
    <div class="12u$">

      <input type="text" id="attribute" >
      <input type="text" id="value" >
    </div>

      <div class="12u$">
        <ul class="actions">
          <li><input type="submit" value="Submit" class="special" /></li>
          <li><input type="reset" value="Reset" /></li>
        </ul>
      </div>
    </form>

Controller

public function store()
    {
        dd(request()->all());
}

route

Route::post('/stimulus/create/attribute', 'Attributes@store');

When I press submit I receive

    array:1 [▼
  "_token" => "K4TSq9lVQq8etkH8lPDxfUJ8g9oF58wm2kJ2pwlz"
]

But nothing else. I'm really unsure what I'm missing here!

You are missing the name attribute on both of the input element inside the form

   <input type="text" name="attribute" id="attribute" /> 
                       ^
   <input type="text" name ="value" id="value" />
                       ^

and then fix the store function inside controller

public function store(Request $request) 
{
    dd(request()->all());
}

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