PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 13, 2022

[FIXED] How to set the value of Tinymce in CakePHP

 January 13, 2022     cakephp, javascript, php, tinymce     No comments   

Issue

I am using CakePHP 2.4.1 and Tinymce for CakePHP2. I have an Edit page and I want to give some default text (extracted from the database) to one of the <textarea>'s. Using plain Cake code I have this:

echo $this->Form->input('conditii_plata',array(
    'value'=>$conditii_plata[0]['Setare']['value'], 
    'escape'=>false,
    'type' => 'textarea',
));

My question: If I convert it to Tinymce I can't give it a default value. Is this possible to do?


Solution

No, you cannot without setting the text from Javascript upon TinyMCE init.

You could make your textarea hidden and have a second textarea deal with TinyMCE In your document ready javascript function:

tinymce.init({
    selector: '<id of your second textarea>',
    ....
    setup : function(editor){
        editor.on('init', function(e){
            //copy from hidden textarea
            editor.setContent($('<1st textarea id').val());
        });
    });
});

Then your should manually submit your form and before sending copy the tinymce content to your hidden textarea.

Another aproach is to encode your data to json and deal with it from javascript.



Answered By - kcsoft
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing