我在Laravel有这个表格:
<form method="post">
{{csrf_field()}}
<button type="submit" value="happy" id="happy" name="reaction" class="border-0 btn-submit">
<img src="/assets/images/reactions/happy.png" />
</button>
<button type="submit" value="angry" id="angry" name="reaction" class="border-0 btn-submit">
<img src="/assets/images/reactions/angry.png" />
</button>
<button type="submit" value="ill" id="ill" name="reaction" class="border-0 btn-submit">
<img src="/assets/images/reactions/ill.png" />
</button>
<button type="submit" value="love" id="love" class="border-0 btn-submit">
<img src="/assets/images/reactions/in-love.png" />
</button>
<button type="submit" value="quiet" id="quiet" class="border-0 btn-submit">
<img src="/assets/images/reactions/quiet.png" />
</button>
<button type="submit" value="sad" id="sad" class="border-0 btn-submit">
<img src="/assets/images/reactions/sad.png" />
</button>
<!-- <input type="text" name="studentName" id="studentName" class="form-control" placeholder="please type in your name"> -->
<input type="hidden" value="{{$article->id}}" id="post_id">
<input type="hidden" name="_token" value="{{csrf_token()}}">
</form>
在我进入控制器后,从帖子中获取所有数据不起作用:
$request->request->all(); //Get all post requests
switch ($request->request->input('reaction')) {
case 'happy':
return response()->json(['success' => "happy"]);
break;
case 'angry':
return response()->json(['success' => "angry"]);
break;
case 'ill':
return response()->json(['success' => "ill"]);
break;
}
我正在一一尝试这些代码,但它没有给我结果,而只是给我一个结果:
return $request->all();
$request->request->get('my_param');
$request->request->post('my_param');
$request->request->input('my_param');
但是没有工作!我厌倦了尝试获取按钮值或输入值。