PHP - TinyMCE Problem
Posted: Sun Mar 30, 2014 12:04 am
I have searched for a solution to this problem and the tinymce website is not big on support unless you spend money. I updated to the recent version of TinyMCE 4.0.20. The problem I am having is that when I type something and hit submit it is not saving it to the database. It closes like it is going to save it but it does not save it. Here is the code.
Form Handler:
Form:
I had an older version of tinymce installed which is causing problems so i decided to update the code. Everything works except it will not save to the database when the form is submitting. Any help on this to solve this problem is very much appreciated.
Form Handler:
Code: Select all
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#edit').submit(function(e) {
e.preventDefault();
var id = "<?php echo $Sys->Template->getData('block_id'); ?>";
var type = $('#type').val();
<?php if ($Sys->Template->getData('block_type') == 'wysiwyg') { ?>
tinyMCE.triggerSave();
<?php } ?>
var content = $('#field').val();
var dataString = 'id=' + id + '&field=' + content + '&type=' + type;
$.ajax({
type: "POST",
url: "core/cms/edit.php",
data: dataString,
cache: false,
success: function(html) {
$('#cboxLoadedContent').html(html);
}
});
});
$('#cms_cancel').on('click', function(){
if (tinyMCE.getInstanceById('field')) {
tinyMCE.execCommand('mceFocus', false, 'field');
tinyMCE.execCommand('mceRemoveControl', false, 'field');
}
$(this).colorbox.close();
});
});
</script>
<?php
global $Sys;
if ($Sys->Template->getData('block_type') == 'wysiwyg')
{ ?>
<script type="text/javascript">
tinymce.init({
mode: "textareas",
width: 820,
height: 500,
plugins: [
"advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"table contextmenu directionality emoticons template textcolor paste fullpage textcolor"
],
toolbar1: "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",
toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media code | inserttime preview | forecolor backcolor",
menubar: false,
toolbar_items_size: 'medium',
style_formats: [
{title: 'Bold text', inline: 'b'},
{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
{title: 'Example 1', inline: 'span', classes: 'example1'},
{title: 'Example 2', inline: 'span', classes: 'example2'},
{title: 'Table styles'},
{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
],
templates: [
{title: 'Test template 1', content: 'Test 1'},
{title: 'Test template 2', content: 'Test 2'}
],
// Example content CSS (should be your site CSS)
content_css : "css/style.css, css/tinymce.css"
});
setTimeout(function() {tinyMCE.execCommand('mceAddControl', false, 'field');}, 0);
</script>
<?php } ?>Code: Select all
<div id="cb_wrapper">
<h2>Edit Content Block: <i><?php echo $Sys->Template->getData('block_id'); ?></i></h2>
<form action="" method="post" id="edit">
<fieldset>
<div class="row">
<label for="field">Block Content: </label>
</div>
<div class="row">
<?php echo $Sys->Template->getData('cms_field'); ?>
<input type="hidden" id="type" value="<?php $Sys->Template->getData('block_type'); ?>" />
</div>
<div class="row submitrow">
<input type="submit" name="submit" class="submit" value="Save" />
<a href="#" id="cms_cancel">Cancel</a>
</div>
</fieldset>
</form>
</div>