Page 1 of 1

PHP - TinyMCE Problem

Posted: Sun Mar 30, 2014 12:04 am
by PhpExile
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:

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 } ?>
Form:

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" />
        &nbsp;<a href="#" id="cms_cancel">Cancel</a>
        
    </div>
    </fieldset>
    </form>

</div>
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.

Re: PHP - TinyMCE Problem

Posted: Sun Mar 30, 2014 6:52 am
by PhpExile
Btw...that is all one script thats why the action="" is empty

Re: PHP - TinyMCE Problem

Posted: Sun Mar 30, 2014 7:05 am
by Celauran
What's $Sys? You're declaring it as global after already having tried to use it above in your jQuery. Does it need to be defined as global? Is he jQuery correct?

Re: PHP - TinyMCE Problem

Posted: Sun Mar 30, 2014 7:49 am
by PhpExile
$Sys is the variable that calls the class Core which calls all the other classes. All that works the main thing is TinyMCE is not saving. When you are logged in as an admin on the website you are able to click the content on the home page. If it is set to wysiwyg then it includes the tinymce which loads the content from the database correctly but when the content is changed it does not upload the added content at all. Here is the edit.php in the url: "core/cms/edit.php" inside ajax:

Code: Select all

<?php

require('../config.php');

$Sys->Auth->chkAuth();

global $Sys;

if(isset($_POST['field']) && (isset($_POST['id']) == FALSE || isset($_POST['type']) == FALSE)) {
	
	$Sys->Template->error('', 'Hack Attempt: Your IP has been recorded.');
	exit;
	
}
elseif(isset($_POST['field'])) {
	
	// Get Data
	$id = $Sys->Cms->clean_block_id($_POST['id']);
	$Sys->Template->setData('block_id', $id);
	
	$type = htmlentities($_POST['type'], ENT_QUOTES);
	$content = $_POST['field'];
	
	unset($_POST['field']);
	
	$Sys->Cms->update_block($id, $content);
	
	// Refresh Page
	$Sys->Template->load(VIEW . "vsaving" . php_ext);
		
}
else {
	
	if(isset($_GET['id']) == FALSE || isset($_GET['type']) == FALSE) {
		
		$Sys->Template->error('unauthorized');
		exit;
	
	}
	
	$id = $Sys->Cms->clean_block_id($_GET['id']);
	$type = htmlentities($_GET['type'], ENT_QUOTES);
	
	$content = $Sys->Cms->load_block($id);
	
	$Sys->Template->setData('block_id', $id);
	$Sys->Template->setData('block_type', $type);
	$Sys->Template->setData('cms_field', $Sys->Cms->generate_field($type, $content), FALSE);
	
	//Load the view
	$Sys->Template->load(VIEW . 'vedit' . php_ext);
	
}
It is just simply not saving the added content inside TinyMCE.

Re: PHP - TinyMCE Problem

Posted: Sun Mar 30, 2014 7:50 am
by PhpExile
The old version is saving just fine but when i convert over to the new version of tinymce it won't save

Re: PHP - TinyMCE Problem

Posted: Mon Mar 31, 2014 11:27 pm
by PhpExile
Anyone know why its not saving to the database?

Re: PHP - TinyMCE Problem

Posted: Tue Apr 08, 2014 10:00 am
by PhpExile
bump...it has something to do with the tinymce code only not the php. Just need to know why its not sending it through the ajax then to the database. Thanks.

Re: PHP - TinyMCE Problem

Posted: Fri Apr 11, 2014 9:49 am
by pickle
Is content being populated properly with what you'd expect?

Is the data being sent to the browser like you'd expect? Firebug or Chrome dev tools can show you the content of your AJAX requests & their replies.