This question already has answers here:
Add icon to Laravelcollective submit button
(3 answers)
Closed 2 years ago.
#can('user-delete')
{!! Form::open(['method' => 'DELETE','route' => ['users.destroy', $user->id],'style'=>'display:inline']) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-default']) !!}
{!! Form::close() !!}
#endcan
I need to display fa icon instead of DELETE text in the button,
<i class="fas fa-trash-alt"></i>
How can I display this fa icon in that button.
I'm using laravel and bootstrap 4.
Use the Form::button instead of Form::submit to achieve this:
{{ Form::button('<i class="fas fa-trash-alt"></i>', ['class' => 'btn btn-default', 'type' => 'submit']) }}
Then you can simply add the type to submit to the button instance.
You can use something like this:
<div class="input-group margin-bottom-sm">
<span class="input-group-addon"><i class="fa fa-trash-alt"></i></span>
{!! Form::button('name if you need', array('class' => 'form-control') ) !!}
</div>
into your Form::button array you can use everything you need such as 'type'=>'submit'
Related
I am using laravel collctive form. I want to update only the quantity field of the following form keeping the blood_id field readonly. When I submit the form I am not getting blood_id value.
How can i solve it?
{!! Form::model($bloodBank, ['route' => ['bloodBanks.update', $bloodBank->id], 'method' => 'put']) !!}
<div class="row">
<div class="col-lg-8">
<div class="form-group">
{!! Form::label('blood_id', 'Blood Group', ['class' => 'form-control-label']);!!}
{!! Form::select('blood_id', $bloods , null , ['placeholder' => 'Choose Blood Group',"class"=>"form-control",'disabled' => true]) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="form-group">
{!! Form::label('quantity','Quantity', ['class' => 'form-control-label']);!!}
{!! Form::number("quantity",null, ["class"=>"form-control form-control-label",'min'=>'0']) !!}
<span class="validation-error">{{ $errors->first("quantity") }}</span>
</div>
</div><!-- col-12 -->
</div>
<button class="btn btn-info">Update </button>
{!! Form::close() !!}
For disabled fields, you may want to add hidden fields which won't display on the rendered page BUT will be included in the request object. E.g.
{{ Form::hidden('blood_id', $bloods) }}
This is in addition to the displayed field you already have which is disabled.
In Laravel, I'd like my delete button to add a confirm option to it:
{!!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()!!}
This is the code in which I would like to add a confirmation popup which would ask you to confirm if you want to delete.
You can replace this to your button.
{!!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()!!}
Here's a snippet I'm always using in my projects. It's a default web browser alert pop-up. It creates a hidden form and appends the ID of the property you want to delete to it.
<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>
how can I create a select box which is filled with values from the db?
The view is published with the $groups variable. In my select box i need $groups->id (hidden, only for storing) and $groups->name. This is currently my form.
{!! Form::open(array('route'=>'store.invitation')) !!}
<div class="form-group">
{{Form::label('username', 'Username')}}
{{Form::text('username', '', ['class' => 'form-control', 'placeholder' => 'Enter Username'])}}
{{Form::label('groupname', 'Gruppe')}}
{{Form::select($groups->name) }}
{{ csrf_field() }}
</div>
<div>
{{Form::submit('Submit',['class' => 'btn btn-primary'])}}
<a class="btn btn-default btn-close" href="{{ route('home') }}">Cancel</a>
</div>
{!! Form::close() !!}
Thanks
You should pass an array of the data that you get from the db. Like this:
Form::select('size', array('L' => 'Large', 'S' => 'Small'));
This documentation might be old, but thats how you can create Form::select in blade.
I'm making a twitter look-a-like app.
I have a form to post a message on 1 blade (createMessage.blade.php) which is as followed:
#section('message')
{!! Form::open(['url' => 'message/postmessage']) !!}
<div class="form-group col-lg-6 col-lg-offset-3">
{!! Form::label('body') !!}
{!! Form::textarea('body', null,['class' => 'form-control']) !!}
</div>
<div class="form-group col-lg-6 col-lg-offset-3">
{!! Form::submit('Post message', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
#endsection`
Now I want to get my form on different pages (such as my timeline) but if I try #yield('message') it doesn't work.
timeline:
#extends('layouts.app')
#section('content')
#yield('message')
//some code for my timeline
#endsection
I can't find out why it doens't work.
Thanks in advance!
You have to use
#include('createMessage.blade.php') in the timeline file and remove the #section declaration in createMessage.blade.php
Below is the output of form.
I want to keep this both 2 fields in a one row. How can I do that using bootstrap? This is my view code.
{!! Form::label('titles', 'Title') !!}
{!! Form::text('title',null,['class' => 'form-control']) !!}
You can try like this:
<div class="form-group col-md-1">
{!! Form::label('titles', 'Title') !!}
</div>
<div class="form-group col-md-11">
{!! Form::text('title',null,['class' => 'form-control']) !!}
</div>