在Laravel表单上用图标替换提交按钮

时间:2018-08-15 11:39:50

标签: php laravel forms font-awesome

问题: 我正在使用laravel表单向数据库发出DELETE请求,现在我有一个submit字段,Laravel包含了该字段,但我想显示一个图标。

代码:

{!! Form::open(['action' => ['TasksController@destroy', $task->id],'method' => 'POST', 'class'=> 'float-right']) !!}

    {{Form::hidden('_method','DELETE')}}
    {{Form::submit('Delete', ['class' => 'btn btn-outline-danger'])}}

{!! Form::close() !!} 

我想要的:

{{Form::submit('Delete', ['class' => 'btn btn-outline-danger'])}}

// want to replace submit field with icon

<i class="far fa-trash-alt icon-size"></i>

2 个答案:

答案 0 :(得分:2)

您可以使用此:

{{Form::button('<i class="far fa-trash-alt icon-size"></i>', ['type' =>'submit', 'class' => 'submit-btn'])}}

具有隐藏按钮的样式:

.submit-btn {
    padding:0;
    background: none;
    border:none;
}

代替:

{{Form::submit('Delete', ['class' => 'btn btn-outline-danger'])}} 

答案 1 :(得分:1)

您可以将表单包裹一些东西,隐藏起来,然后通过js提交。像这样:

<style>.form-wrapper>form{/*hide the form, change cursor to pointer, etc*/}</style>
<div class="form-wrapper" onclick="$(this).getElementsByTagName('form')[0].submit()">
    <i class="far fa-trash-alt icon-size"></i>
    {!! Form::open(['action' => ['TasksController@destroy', $task->id],'method' => 'POST', 'class'=> 'float-right']) !!}
        {{Form::hidden('_method','DELETE')}}
        {{Form::submit('Delete', ['class' => 'btn btn-outline-danger'])}}
    {!! Form::close() !!}
</div>