I have a form that I'm trying to pass through to update a page. My name and title are passed through; however, but my textarea does not. The code I'm using to pass the data
<script>
$(function () {
$('#updater').on('click', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'calls.php',
data: $('#updatepage').serialize(),
success: function (data) {
alert(data);
location.reload();
}
});
});
});
</script>
And then my actual form is
<form id="updatepage">
<input id="process" name="process" value="updatepage" type="hidden">
<input id="id" name="id" value="<?php echo $_GET['id']; ?>" type="hidden">
<table><tr><td>Name</td><td>Title</td></tr>
<tr><td><input type='text' name='name' id='name' value='<?php echo $admin->PageName(); ?>'></td>
<td><input type="text" name="title" id="title" value = "<?php echo $admin->PageTitle(); ?>"></td>
</tr>
</table>
<!-- tools box -->
<div class="pull-right box-tools">
<button class="btn btn-info btn-sm" data-widget='collapse' data-toggle="tooltip" title="Collapse"><i class="fa fa-minus"></i></button>
<button class="btn btn-info btn-sm" data-widget='remove' data-toggle="tooltip" title="Remove"><i class="fa fa-times"></i></button>
</div><!-- /. tools -->
</div><!-- /.box-header -->
<div class='box-body pad'>
<textarea id="editor1" name="editor1" rows="10" cols="80"><?php $admin->PageContent(); ?></textarea>
<a class="btn btn-app" id="updater">
<i class="fa fa-save"></i> Save
</a>
</form>
When I pass the data on the input ids are passed, but not matter what I do it seems my textarea always believes it's empty. The function that's called on the submission:
public function UpdatePage() {
global $db;
$query = <<<SQL
UPDATE pages
SET name=:name,title=:title,content=:content
WHERE id = :id
SQL;
$resource = $db->sitedb->prepare( $query );
$resource->execute( array(
':name' => $_POST['name'],
':title'=> $_POST['title'],
':content' => $_POST['editor1'],
':id' =>$_POST['id'],
));
}
The problem lies within CK editor. For some reason attaching CK editor is making it so that it doesn't pass. Now I just have to find out why that is. The AJAX that's been modified to work with CKeditor $(function () {
$('#updater').on('click', function (e) {
for ( instance in CKEDITOR.instances )
CKEDITOR.instances[instance].updateElement();
e.preventDefault();
$.ajax({
type: 'post',
url: 'calls.php',
data: $('#updatepage').serialize(),
success: function (data) {
alert(data);
location.reload();
}
});
});
});
</script>