Search code examples
csslaravelfont-awesomelaravel-form

Using Font Awesome in Laravel's Forms Submit button?


I have the following form that works as a 'Delete' button.

{{ Form::open(['method' => 'DELETE', 'route' => ['notes.delete', $note->user->id]]) }}
{{ Form::submit('Delete', ['class' => 'btn btn-warning btn-sm']) }}
{{ Form::close() }}

Is there a way to replace the "Delete" button text with a Font Awesome icon? I tried changing it to:

{{ Form::submit('<i class="fa fa-minus-circle" aria-hidden="true"></i>', ['class' => 'btn btn-warning btn-sm']) }}

However, it does not display the icon, but just the raw version of HTML code - <i class="fa fa-minus-circle" aria-hidden="true"></i>. Is there a way to use Font Awesome with Laravel forms?


Solution

  • When you use Form::submit, the contents are always escaped. You can use Form::button instead, which does not escape the content.

    {{ Form::button('<i class="fa fa-minus-circle" aria-hidden="true"></i>', ['class' => 'btn btn-warning btn-sm', 'type' => 'submit']) }}
    

    Important to notice here is 'type' => 'submit' added after class.