Custom Web Applications to Grow Your Business

(256) 429-8145

Cakephp admin only image upload option in Ckeditor Form

There are times when both admin and regular users will use the same form; for example, in a blog post comment form.

Due to securities concerns admin may want access to image upload or other ckeditor plugin on the form, but concurrently prevent regular members access to those plugin features.

Here is a simple way to do just that

1. Include CKeditor at the top of the page:

Html->script('ckeditor/ckeditor'); ?>

2. Set up form inputs. In this case, there is no need to include the Ckeditor class in the text area.

<?php echo $this->Form->create('Post'); ?>
<?php  echo $this->Form->input('id');                                           
echo $this->Form->input('content', array('id' => 'content'));
echo $this->Form->end('Add');
?>

Include this script below your form. Change "Image" to the name of the plugin you want to grant access to only to admin

<script>

CKEDITOR.replace( 'question', { toolbar : [ { name: 'basicstyles', items : [ 'Bold','Italic', 'Underline' ] }, { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent'] }, { name: 'links', items : [ 'Link','Unlink'] }, { name: 'editing', items: [ 'find', 'selection', 'spellchecker' ] }, { name: 'tools', items : ['Image','Source', <?php $this->Session->read('Auth.User.role') == 'admin') { echo "'Image',";}?>'-'] } ] });

</script>