Sebuahhobi98

csrf_regenerate

Jul 16th, 2019
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. <!-- Modal Tambah dan Edit DATA-->
  2. <div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  3. <div class="modal-dialog modal-dialog-centered" role="document">
  4. <div class="modal-content">
  5. <div class="modal-header">
  6. <h5 class="modal-title" id="Label_Head">Tambah Data</h5>
  7. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  8. <span aria-hidden="true">&times;</span>
  9. </button>
  10. </div>
  11. <div class="modal-body">
  12. <input type="hidden" id="sh_csrf" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
  13. <div class="form-group">
  14. <label>Kamar<span class="text-danger" id="message_kamar"></span></label>
  15. <input type="text" class="form-control" id="kamar" placeholder="Kamar">
  16. </div>
  17. <div class="form-group">
  18. <label>Isi Max<span class="text-danger" id="message_isi_max"></span></label>
  19. <input type="text" class="form-control" id="isi_max" placeholder="Isi Max">
  20. </div>
  21. <div class="form-group">
  22. <label>Status<span class="text-danger" id="message_status"></span></label>
  23. <input type="text" class="form-control" id="status" placeholder="Status">
  24. </div>
  25. <div class="form-group">
  26. <label>Kondisi<span class="text-danger" id="message_kondisi"></span></label>
  27. <input type="text" class="form-control" id="kondisi" placeholder="Kondisi">
  28. </div>
  29. <div class="form-group">
  30. <label>Perlengkapan<span class="text-danger" id="message_perlengkapan"></span></label>
  31. <input type="text" class="form-control" id="perlengkapan" placeholder="Perlengkapan">
  32. </div>
  33.  
  34. </div>
  35. <div class="modal-footer">
  36. <button type="button" class="btn btn-secondary" data-dismiss="modal">Keluar</button>
  37. <div id="button_action">
  38.  
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44.  
  45.  
  46. <script>
  47. var token = $('#sh_csrf').val();
  48. var id_data='';
  49. function f_edit(id){
  50. //$('#form_modal').prop("action","<?php echo base_url(); ?>kamar_akhwat/update");
  51. $.ajax({
  52. url : '<?php echo base_url();?>kamar_akhwat/update',
  53. cache : false,
  54. dataType : 'json',
  55. type : 'post',
  56. data : {id:id, <?php echo $this->security->get_csrf_token_name(); ?> : '<?php echo $this->security->get_csrf_hash(); ?>'},
  57. success : function (data){
  58. //kosongkan inputan
  59. kosong();
  60. //kosongkan pesan error
  61.  
  62. token = data.token;
  63. message();
  64. if(data.ajax=='Sukses'){
  65. id_data=data.id;
  66. $('#kamar').val(data.kamar);
  67. $('#isi_max').val(data.isi_max);
  68. $('#status').val(data.status);
  69. $('#kondisi').val(data.kondisi);
  70. $('#perlengkapan').val(data.perlengkapan);
  71. empty_button_modal();
  72. $('#button_action').html('<button type="button" class="btn btn-primary" id="s_edit" onclick="s_edit()">Edit Data</button>');
  73. $('#Label_Head').html('Edit Data');
  74. show_modal();
  75. }else{
  76. $('#message_succes').html(data.ajax);
  77. }
  78. },
  79.  
  80. });
  81. $('#sh_csrf').val(token);
  82. }
  83. </script>
  84.  
  85.  
  86.  
  87. //controllers
  88. public function update()
  89. {
  90. $this->session->set_userdata('sh_csrf',$this->security->get_csrf_hash());
  91. $id= $this->input->post('id');
  92. $row = $this->Kamar_akhwat_model->get_by_id($id);
  93.  
  94. if ($row) {
  95. $data = array(
  96. 'button' => 'Update',
  97. 'action' => site_url('kamar_akhwat/update_action'),
  98. 'home' => site_url(),
  99. 'href' => site_url('kamar_akhwat'),
  100. 'data_href' => "Al-Qur'an ",
  101. 'this_point' => "Update",
  102. 'ajax' => "Sukses",
  103. 'id' => set_value('id', $row->id),
  104. 'kamar' => set_value('kamar', $row->kamar),
  105. 'isi_max' => set_value('isi_max', $row->isi_max),
  106. 'status' => set_value('status', $row->status),
  107. 'kondisi' => set_value('kondisi', $row->kondisi),
  108. 'perlengkapan' => set_value('perlengkapan', $row->perlengkapan),
  109. 'token' => $this->security->get_csrf_hash()
  110. );
  111. header('Content-Type: application/json');
  112. echo json_encode($data);
  113. } else {
  114. $data=array('ajax'=>'Gagal mengambil data ajax','token' => $this->security->get_csrf_hash());
  115. header('Content-Type: application/json');
  116. echo json_encode($data);
  117. }
  118. }
Add Comment
Please, Sign In to add comment