我想在laravel的Form模式下向我的Delete按钮添加一个确认按钮

问题描述 投票:0回答:2

所以在laravel id中,就像我的删除按钮一样,向其中添加确认选项

{!!Form::open(['action'=>['PostsController@destroy', $posts->id], 'method'=> 'POST', 'class' => 'float-right'])!!}
            {{Form::hidden('_method', 'DELETE')}}
            {{Form::submit('Delete', ['class'=>'btn btn-danger'])}}
{!!Form::close()!!} 

所以这是我想在其中添加构象弹出框的代码,该弹出窗口将要求您确认是否要删除

laravel
2个回答
0
投票

您可以将其替换为按钮。

{!!Form::open(['action'=>['PostsController@destroy', $posts->id], 'method'=> 'DELETE', 'class' => 'float-right'])!!}
     {!! Form::button('Delete', ['type'=>'submit','value'=>'delete','class'=>'btn btn-danger','onclick'=>"return confirm('Are you sure?')"]) !!}
{!!Form::close()!!} 

0
投票

这里是我在项目中经常使用的代码段。这是默认的Web浏览器警报弹出窗口。它创建一个隐藏的表单,并将您要删除的属性的ID附加到该表单中。

<div class="pl-1">
    <button type="button" name="button"
            onclick="if(confirm('Are you sure you want to delete this?')){ $('form#delete-{{$obj->id}}').submit(); }"
            class="btn btn-danger btn-sm">Delete
    </button>
    {!! Form::open(['method' => 'DELETE', 'route' => ['your_route.destroy',$obj->id], 'class' => 'hidden', 'id'=>"delete-".$obj->id]) !!}
    {!! Form::close() !!}
</div>
© www.soinside.com 2019 - 2024. All rights reserved.