Laravel: request before deleting user

I successfully delete entries in my table using the following code. My only problem, I want her to prompt the user to confirm the action before uninstalling.

{{link_to_route('individualprofiles.edit', 'Edit', array($ip->id))}}
{{Form::open(array( 'route' => array( 'individualprofiles.destroy', $ip->id ), 'method' => 'delete', 'style' => 'display:inline'))}}
     {{Form::submit('D', array('class' => 'btn btn-danger'))}}
{{Form::close()}}
+4
source share
3 answers

You can try something like this:

STEP 1

First of all, you need to add the file bootstrap.cssusing the link tag, jQueryand bootstrap.jsusing the script tag in your section of the chapter of your web page. On the bootstraps website you will find detailed information about this. In addition, you can create an individual file with selected components if you do not want to use the full boot infrastructure.

STEP - 2

html- , delete_confirm.php

<!-- Modal Dialog -->
<div class="modal fade" id="confirmDelete" role="dialog" aria-labelledby="confirmDeleteLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Delete Parmanently</h4>
      </div>
      <div class="modal-body">
        <p>Are you sure about this ?</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
        <button type="button" class="btn btn-danger" id="confirm">Delete</button>
      </div>
    </div>
  </div>
</div>

JavaScript ,

<!-- Dialog show event handler -->
  $('#confirmDelete').on('show.bs.modal', function (e) {
      $message = $(e.relatedTarget).attr('data-message');
      $(this).find('.modal-body p').text($message);
      $title = $(e.relatedTarget).attr('data-title');
      $(this).find('.modal-title').text($title);

      // Pass form reference to modal for submission on yes/ok
      var form = $(e.relatedTarget).closest('form');
      $(this).find('.modal-footer #confirm').data('form', form);
  });

  <!-- Form confirm (yes/ok) handler, submits form -->
  $('#confirmDelete').find('.modal-footer #confirm').on('click', function(){
      $(this).data('form').submit();
  });

- 3

, , , , require_once include_once, :

// other code
require_once('delete_confirm.php');

- 4

, - :

<form method="POST" action="http://example.com/admin/user/delete/12" accept-charset="UTF-8" style="display:inline">
    <button class="btn btn-xs btn-danger" type="button" data-toggle="modal" data-target="#confirmDelete" data-title="Delete User" data-message="Are you sure you want to delete this user ?">
        <i class="glyphicon glyphicon-trash"></i> Delete
    </button>
</form>

+8

javascript, . , , javascript .

javascript - , . , .

+1

Using 'onsubmit' => "return confirm('Are you sure you want to delete?')"inside Form::open.

{{Form::open(array( 
    'route' => array( 'individualprofiles.destroy', $ip->id ), 
    'method' => 'delete', 
    'style' => 'display:inline',
    'onsubmit' => "return confirm('Are you sure you want to delete?')",
))}}
     {{Form::submit('D', array('class' => 'btn btn-danger'))}}
{{Form::close()}}
+1
source

All Articles