I'm trying to get Modal by clicking on a button to call my modal with form to add users :
html code:
<button data-toggle="modal" data-target="#mymodal" data-id="<?php echo 'manager_user/user_add';?>" id="menu" class="btn btn-sm btn-primary">
Add User</button>
and in my Modal form the input with csrf name & hash is inserted !
<input type="hidden" name="csrf_token" value="<?=$this->security->get_csrf_hash();?>">
ajax #menu is called by the button above.
$(document).ready(function() {
$(document).on('click', '#menu', function(e) {
e.preventDefault();
var url = $(this).data('id'); // it will get action url
$('#dynamic-content').html(''); // leave it blank before ajax call
$('#modal-loader').show(); // load ajax loader
$.ajax({
url: url,
type: 'POST',
dataType: 'html'
})
.done(function(data) {
console.log(data);
$('#dynamic-content').html('');
$('#dynamic-content').html(data); // load response
$('#modal-loader').hide(); // hide ajax loader
})
.fail(function() {
$('#dynamic-content').html('<i class="glyphicon glyphicon-info-sign"></i> Something went wrong, Please try again...');
$('#modal-loader').hide();
});
});
});
$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_token';
$config['csrf_cookie_name'] = 'csrf_cookie_token';
$config['csrf_expire' ] = 7200;
$config['csrf_regenerate'] = FALSE;
When i turn csrf_protection to FALSE it works
I did also add a meta to my header !! so when I click to show my modal to add user I get 403 Forbidden ERROR.
and Error AJAX Message : Something went wrong, Please try again...
how to I resolve the csrf issue?