Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Hamelraj's avatar

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() !!}
0 likes
13 replies
andrewb's avatar

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>
2 likes
Mo7sin's avatar

You can change it to normal a tag

<a class="btn btn-primary form-control" href="{{ route('consignees.index') }}">{!! $cancel !!}</a>
2 likes
Hamelraj's avatar

@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 ?

Mo7sin's avatar

Try to remove form-control class

<a class="btn btn-primary" href="{{ route('consignees.index') }}">{!! $cancel !!}</a>
1 like
Hamelraj's avatar

@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>
Snapey's avatar

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.

Mo7sin's avatar

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>
1 like
Hamelraj's avatar

ya you correct {!! $cancel!!} but still button up and down :(

Prullenbak's avatar

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).

1 like
Mo7sin's avatar

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>
1 like
Snapey's avatar

Your column is declared col-md-2 so it is probably not wide enough to hold two buttons side by side.

Please or to participate in this conversation.