views:

165

answers:

2

I'm using TinyMCE and want to execute a php script get the output and post the output.
I'm trying to insert my code with data pre-populated by a php script.

Can someone help me with this. I'm a JavaScript novice..

This is my code to insert single instances without data. (The rest of the code is straight from the example on the documentation api)

///////////////////////////////////////////////////////////////////////////////
      ed.addCommand('mceCommandHere', function() {
      ed.execCommand('mceInsertContent',false,'[CODEHERE ="" URL ="" Title=""]'); 
      });
      ed.addButton('CommandHere', {
       title : 'Add Subscriptions',
       cmd : 'mceCommandHere',
       image : url + '/PictureHere.png'
      });
      ed.onNodeChange.add(function(ed, cm, n) {
       cm.setActive('CommandHere', n.nodeName == 'IMG');
      });
      ///////////////////////////////////////////////////////////////////////////////
A: 

not sure what you mean, but php always executes before js, unless you have some ajax going on. so you could insert your database content right into the textarea tag that is used by tinymce

 <textarea name="content"><?php echo $my_data ?></textarea>
antpaw
Thanks for the input, that's not what I was looking for. I needed it to input with a button click. Thanks for the help anyways.
Brad
A: 

I figured it out! YEAH! It only look me 2 days to do it!

      ///////////////////////////////////////////////////////////////////////////////
  ed.addCommand('mceCommandHere', function() {
   var mydata;
    tinymce.util.XHR.send
    ({
             url :  url + "/CommandHere.php",
          content_type : "text/html",
          type : "GET",
         data : tinymce.util.JSON.serialize({
              param1 : "TinyMCE"
          }),
          async : false,
          scope : ed,

          success : function( data, req, o ) {
             mydata = data;
          },

          error : function( type, req, o ){
              alert('Something Went Wrong, Please Check your Installation.  Error Type: '+ type +' Error Status: '+req.status ); 
          }
    });

  ed.execCommand('mceInsertContent',false, mydata ); 
  });
  ed.addButton('CommandHere', {
   title : 'CommandHere',
   cmd : 'mceCommandHere',
   image : url + '/CommandHere.png'
  });
  ed.onNodeChange.add(function(ed, cm, n) {
   cm.setActive('CommandHere', n.nodeName == 'IMG');
  });
  ///////////////////////////////////////////////////////////////////////////////
Brad