How to add cancel button next to save button in Laravel form ? When i use this cancel button also works like a save button i want use same form ** create and edit **
My FORM
<div class="row">
<div class="form-group">
<div class="col-md-2 col-md-offset-8">
<submitfiled>
{!! Form::submit($submit_text,['class'=> 'btn btn-primary form-control']) !!}
</submitfiled>
<submitfiled>
{!! Form::submit($cancel,array('class'=> 'btn btn-primary form-control','route' => 'consignees.index')) !!}
</submitfiled>
</div>
</div>
</div>
My create view
{!! Form::model(new App\Consignee, ['route' => ['consignees.store'],'class'=>'form-horizontal','role'=>'form']) !!}
@include ('consignees/form', ['submit_text' => 'Save','cancel'=>'Cancel'])
{!! Form::close() !!}
Adding a second submit button isn't going to work, it's always going to submit the form to the "action" path of your form.
If you're using Bootstrap, just add a cancel link, which you can style to look like a button using the relevant classes...
<a href="/go-somewhere-else" class="btn btn-default">Cancel</a>
You can change it to normal a tag
<a class="btn btn-primary form-control" href="{{ route('consignees.index') }}">{!! $cancel !!}</a>
@andrewb @ Mo7sin itried this way its working but i couldn't arrange my button next to the save button its alwys in up and down but i want next to the save button you can chek my form can you give me idea ?
Try to remove form-control class
<a class="btn btn-primary" href="{{ route('consignees.index') }}">{!! $cancel !!}</a>
@Mo7sin what is this and where to use ....? form or create view ???
{!! $cancel !!}
now its my form look like ans still button up and down
<div class="row">
<div class="form-group">
<div class="col-md-2 col-md-offset-8">
<submitfiled>{!! Form::submit($submit_text,['class'=> 'btn btn-primary form-control']) !!}</submitfiled>
<a class="btn btn-danger " href="{{ route('consignees.index') }}"><i class="fa fa-btn fa-bank"></i>Cancel</a>
</div>
</div>
</div>
another way is to receive the form and first check if the cancel button had been used. If so, ignore the request and redirect somewhere else.
01 - That $cancel var is what you already passing to form view.
@include ('consignees/form', ['submit_text' => 'Save','cancel'=>'Cancel'])
02 - You need to remove both form-control class in both buttons
<div class="row">
<div class="form-group">
<div class="col-md-2 col-md-offset-8">
<submitfiled>{!! Form::submit($submit_text,['class'=> 'btn btn-primary']) !!}</submitfiled>
<a class="btn btn-danger " href="{{ route('consignees.index') }}"><i class="fa fa-btn fa-bank"></i>Cancel</a>
</div>
</div>
</div>
ya you correct {!! $cancel!!}
but still button up and down :(
What is your
<submitfiled>
tag? That's probably a block element, which makes it use it's own line. If you don't need it, remove it. If you do, you have to fix it in css (probably floats, or display:inline).
I'm not sure if you have any custom CSS but this should work fine!
<div class="row">
<div class="form-group">
<div class="col-md-2 col-md-offset-8">
{!! Form::submit($submit_text,['class'=> 'btn btn-primary']) !!}
<a class="btn btn-danger" href="{{ route('consignees.index') }}"><i class="fa fa-btn fa-bank"></i>Cancel</a>
</div>
</div>
</div>
@Mo7sin thnks but same thing button up and down no css for this :(
Your column is declared col-md-2 so it is probably not wide enough to hold two buttons side by side.
Please sign in or create an account to participate in this conversation.