David David - 5 months ago 69
PHP Question

Confirm delete with laravel form?

Problem with confirm delete, all works fine, but if you click cancel in confirm popup it will delete the item from DB. Any ideas? Please show with code example, I'm new to laravel.


function ConfirmDelete()
var x = confirm("Are you sure you want to delete?");
if (x)
return true;
return false;


{!! Form::open(['method' => 'DELETE', 'route' => ['path_delete_time', $time->id], 'onsubmit' => 'ConfirmDelete()']) !!}

{!! Form::hidden('case_id', $project->id, ['class' => 'form-control']) !!}

{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', array('type' => 'submit', 'class' => 'specialButton')) !!}

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


Just add return to your onsubmit call. so the value the function returns determines if the form gets submitted or not.

'onsubmit' => 'return ConfirmDelete()'