使用拉拉维尔表单确认删除?

2022-08-31 00:17:07

确认删除问题,一切正常,但如果您在确认弹出窗口中单击取消,它将从数据库中删除该项目。有什么想法吗?请用代码示例显示,我是laravel的新手。

<script>

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

</script>

{!! 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() !!}

答案 1

只需将回传添加到您的通话中即可。因此,函数返回的值确定表单是否提交。onsubmit

'onsubmit' => 'return ConfirmDelete()'

答案 2

简单地将jQuery代码放在提示框时提交表单或删除记录。

jQuery(document).ready(function($){
     $('.deleteGroup').on('submit',function(e){
        if(!confirm('Do you want to delete this item?')){
              e.preventDefault();
        }
      });
});

推荐