samedi 29 avril 2017

Laravel 5.4: Delete Modal Not Obtaining Object

So I have a table of people, with each column containing certain values. At the end of each row, I have a "Delete" button. When that button is pressed, a modal pops up to confirm if you want to proceed with deleting that person. Clicking the "Delete" button again should delete the person and display a success message for it.

With the modal, I'm trying to make sure not only that a user needs to accept the action before proceeding, but also making sure that only the specific person in question is deleted. However, when I try to clarify the request it only contains the CSRF token that I'm passing through. Even when I try to more deliberately inject the targeted person into the modal the person isn't being sent through.

The important snippets of my code, for reference:

@foreach($people as $person)
   <tr id="row">
       <td id="first_name_row"></td>
       <td id="last_name_row"></td>
       <td id="email_row"></td>
       <td>
         <input type="button" id="delete_button_row" class="btn btn-btn-submit delete" value="Delete" onclick="delete_modal('', )">
       </td>
   </tr>
@endforeach

..........

<!-- Modal -->
    <div class="modal fade" id="DeleteModal" role="dialog">
        <div class="modal-dialog">
            <form class="form-horizontal style-form" id="model-form" data-toggle="validator" role="form" method="post" action="/employer/delete-person">
              <!-- Modal content-->
              
              <div class="modal-content">

                  <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal">&times;</button>
                      <h4 class="modal-title">Delete This Person</h4>
                  </div>
                  <div class="modal-body">
                      <p>Are you sure you would like to do that?</p>
                      <input id="delete_ex">
                  </div>
                  <div class="modal-footer">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                      <button type="submit" id="modal-execute" class="btn btn-btn-submit">Delete</button>
                  </div>
              </div>
          </form>
        </div>
    </div>

......

<script>

  function delete_modal(num, person){
    $('#delete_button_row' + num).attr("data-toggle" , "modal");
    $('#delete_button_row' + num).attr("data-target", "#DeleteModal");
    $('#delete_ex').val(person);
  }

  .......

</script>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire