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.
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. If you want 2 submit buttons going to different actions, you can use theformactionattribute on the submit buttonsFor example:
For more information, see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-formaction