[英]How to use multiple post method in a signle form in laravel blade?
I am working with laravel.I have a form.I want to use two button name submit and save.This two button will work for two post method route.我正在使用 laravel。我有一个表单。我想使用两个按钮名称提交和保存。这两个按钮适用于两个发布方法路线。
Here my form...这是我的表格...
<form action="{{ route('quizSubmit',$sessionId) }}" method="post" class="form-group">
@csrf
@foreach($quizQuestions->questions as $key => $question)
@php
$q = 1+$key
@endphp
<div class="form-group">
{{-- <input type="hidden" class="form-control" name="question[]" value="{{$question->id}}"> --}}
<label class="form-check-label" for="question">Question {{1+$key}}:</label>
<h4>{{$question->name}}</h4>
<input type="hidden" name="questions[{{ $q }}]" value="{{ $question->id }}">
@foreach($question->choices as $key => $choice)
{{-- <label class="form-check-label" for="radio1">
<input name="radio-{{$q}}" type="radio">{{$choice->name}}
</label> --}}
<label>
<input id="choice" type="radio" name="choice[{{$question->id}}]"
value="{{$choice->id}}">
{{$choice->name}}
</label>
@endforeach
</div>
@endforeach
<div class="form-group">
<input type="submit" class="btn btn-primary">
<form action="{{ route('quiz.incomplete',$sessionId) }}" method="post">
@csrf
<input type="submit" class="btn btn-info" value="Save" />
</form>
</div>
</form>
Here the routes.这里的路线。 for submit button.提交按钮。
Route::post('quiz-session-ans/{sessionId}/questions/choices/submit','Web\Site\Quiz\QuizSessionAnsController@store')->name('quizSubmit');
for save button保存按钮
Route::post('quiz-session-ans/{sessionId}/questions/choices/save','Web\Site\Quiz\QuizSessionAnsController@incompleteSession')->name('quiz.incomplete');
But the above code is not working the way that I want.但是上面的代码没有按照我想要的方式工作。 How to solve it?如何解决?
<form>
s cannot be nested inside of each other. <form>
不能相互嵌套。 If you want 2 submit buttons going to different actions, you can use the formaction
attribute on the submit buttons如果您希望 2 个提交按钮执行不同的操作,您可以在提交按钮上使用formaction
属性
For example:例如:
<form method="post">
<button formaction="/url1" type="submit">Submit to /url1</button>
<button formaction="/url2" type="submit">Submit to /url2</button>
</form>
For more information, see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-formaction有关详细信息,请参阅: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-formaction
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.