The Post form inside this table class doesn't respond when submitting
<table class="table table-hover">
<tbody>
<tr>
<th>NO.</th>
<th>NAME.</th>
<th>Telephone</th>
<th>email</th>
<th>date</th>
<th></th>
<th>action</th>
</tr>
@foreach($users as $value)
<tr>
<td>{{$value->id}}</td>
<td>{{$value->firstname}} {{$value->lastname}}</td>
<td>{{$value->phonenumber}}</td>
<td>{{$value->email}}</td>
<td>{{$value->created_at}}</td>
<form method="POST" action="{{ route('admin') }}">
@csrf
<div class="form-group">
{{-- <input type="hidden" name="value" value="{{$value}}"> --}}
@if($value->status == 'Waiting')
<td><button type="submit" name="action" value="Waiting" class="label label-primary">Waiting</span></td>
@else
<td><button type="submit" name="action" value="Approved" class="label label-success">Approved</span></td>
@endif
</div>
</form>
</tr>
@endforeach
</tbody>
</table>
it works outside just under the table and I have no idea why it doesn't work, anyone has any ideas? I also tried using a link button instead but that too doesn't work.
Try to move the form into the <td>
tags. tr > form > td is invalid HTML.
<tr>
<td>{{$value->id}}</td>
<td>{{$value->firstname}} {{$value->lastname}}</td>
<td>{{$value->phonenumber}}</td>
<td>{{$value->email}}</td>
<td>{{$value->created_at}}</td>
<td>
<form method="POST" action="{{ route('admin') }}">
@csrf
<div class="form-group">
{{-- <input type="hidden" name="value" value="{{$value}}"> --}}
@if($value->status == 'Waiting')
<button type="submit" name="action" value="Waiting" class="label label-primary">Waiting</button>
@else
<button type="submit" name="action" value="Approved" class="label label-success">Approved</button>
@endif
</div>
</form>
</td>
</tr>
And your buttons are closed with <span>
tags. Fixed that.
You have mistakenly close your button
element with span
@if($value->status == 'Waiting')
<td><button type="submit" name="action" value="Waiting" class="label label-primary">Waiting</button></td>
@else
<td><button type="submit" name="action" value="Approved" class="label label-success">Approved</button></td>
@endif
thanks.
Make sure the route method used on {{ route('admin') }}
The same code I tested by creating a controller on my end
Route::resource('test', 'TestController');
Blade entry
<table class="table table-hover">
<tbody><tr>
<th>NO.</th>
<th>NAME.</th>
<th>Telephone</th>
<th>email</th>
<th>date</th>
<th></th>
<th>action</th>
</tr>
@foreach($adverts as $value)
<tr>
<form method="POST" action="{{ route('test.store') }}">
@csrf
<div class="form-group">
<input type="hidden" name="id" value="{{$value->id}}">
<td><button type="submit" name="action" value="Approved" class="label label-success">Approved</span></td>
</div>
</form>
</tr>
@endforeach
</tbody></table>
My controller
class TestController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
dd($request->all());
}
NOTE : I pointed the form action to action="{{ route('test.store') }}"
I think the form action you have used is wrong
I think this code helps you.
<table class="table table-hover">
<tbody>
<tr>
<th>NO.</th>
<th>NAME.</th>
<th>Telephone</th>
<th>email</th>
<th>date</th>
<th></th>
<th>action</th>
</tr>
@foreach($users as $value)
<tr>
<td>{{$value->id}}</td>
<td>{{$value->firstname}} {{$value->lastname}}</td>
<td>{{$value->phonenumber}}</td>
<td>{{$value->email}}</td>
<td>{{$value->created_at}}</td>
<td>
<form method="POST" action="{{ route('admin') }}">
<input type="hidden" value="{{csrf_token()}}" name="_token">
<div class="form-group">
{{-- <input type="hidden" name="value" value="{{$value}}"> --}}
@if($value->status == 'Waiting')
<td><button type="submit" name="action" value="Waiting" class="label label-primary">Waiting</button></td>
@else
<td><button type="submit" name="action" value="Approved" class="label label-success">Approved</button></td>
@endif
</div>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
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.