I have a form inside of an iframe in my CodeIgniter application:
<div class="settings"><h2>Einstellungen</h2>
<div class="main-content">
<iframe src="" name="main-content">
<form id="new-role-form" method="post" action="<?php echo base_url('index.php/home/settings') ?>">
<input class="role-input" type="text" placeholder="Rolle" name="role"><input class="role-input" type="password" placeholder="Passwort" name="password"><button class="button role-submit" type="submit"><span class="glyphicon glyphicon-plus"></span></button>
</form>
</iframe>
</div>
</div>
When submitting this form the following code should be executed (the submit is working I tested it; I can get the inputs of the form here):
$(document).on('submit', '#new-role-form', function(event) {
var form = $(this);
var name = $('input[name="role"]', form).val();
var password = $('input[name="password"]', form).val();
$.ajax({
url: '<?php echo base_url('index.php/ajax/insertRole'); ?>',
type: 'POST',
data: {name: name, password: password},
success: function() {
alert("success");
}
});
event.preventDefault();
});
And this is the insertRole function of my ajax controller:
public function insertRole() {
$this->Database->insert($this->input->post('name'), $this->input->post('password'));
}
This is where I get the error: ...index.php/ajax/insertRole 500 (Internal Server Error)
How can I retrieve the POST data from a form inside an iframe?