doesn't work in this

问题描述 投票:1回答:4

提交时,此表类中的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>

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

php laravel laravel-blade
4个回答
1
投票

尝试将表单移动到<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>标签关闭。修正了。


0
投票

你错误地用button关闭你的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

谢谢。


0
投票

确保{{ 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') }}"

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


0
投票

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

<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>
© www.soinside.com 2019 - 2024. All rights reserved.