繁体   English   中英

<form method="post">在这不起作用<table>

[英]<form method="post"> doesn't work in this <table>

此表类中的 Post 表单在提交时没有响应

<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>

它在桌子底下就在外面工作,我不知道为什么它不起作用,有人有什么想法吗? 我也尝试使用链接按钮,但这也不起作用。

尝试将表单移动到<td>标签中。 tr > form > td 是无效的 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>

你的按钮用<span>标签关闭。 修正了那个。

您错误地用span关闭了button元素

                        @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

谢谢。

确保在{{ route('admin') }}上使用的路由方法

我通过在我的一端创建一个控制器来测试的相同代码

Route::resource('test', 'TestController');

刀片入口

<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>

我的控制器

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());
    }

注意:我将表单操作指向action="{{ route('test.store') }}"

我认为您使用的表单操作是错误的

我认为这段代码可以帮助你。

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM