We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9932
    • 66 Posts
    How can I insert TinyMCE into module code?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Here’s the code that makes the KoopsMailinglistX module use the default MODx manager’s RTE (see this post and a few more posts on the subject further up the list of that topic)
      		echo '<div class="content_">
      				<form action="index.php?a=112&id='.$modId.'&p=2" method="post"><b>
      				'.$l_subject.':</b><br/><input type="text" size="50" maxlength="50" name="subject"></input>
      				<br/><br/>'.$l_firefoxproblem.'<br/><br/>	';
      		
      		// Get access to template variable function (to output the RTE)
      		include_once($modx->config['base_path'].'manager/includes/tmplvars.inc.php');
      	  
      		$event_output = $modx->invokeEvent("OnRichTextEditorInit", array('editor'=>$modx->config['which_editor'], 'elements'=>array('tvmailMessage')));
      	
      		if(is_array($event_output)) {
      			$editor_html = implode("",$event_output);
      		}
      		// Get HTML for the textarea, last parameters are default_value, elements, value
      		$rte_html = renderFormElement('richtext', 'mailMessage', '', '', '');
      		
      		echo $rte_html;
      		
      		echo $editor_html;
      		echo  '<br />
      			<input type="submit" value="'.$l_submit.'"></input>
      			</form></div>';
      
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 9932
        • 66 Posts
        thanks, sottwell
        this code is exactly what I need. smiley
          • 168
          • 15 Posts
          Doesn’t work for me, though..

          Using
          $tinymce = $this->modx->invokeEvent('onRichTextEditorInit', array(
              'editor'    => $this->config['which_editor'],
              'elements'  => array('full_text')
          ));
          die(var_dump($tinymce));
          will return (bool) false?

          I have tried the method of this post, using tmplvars.inc.php functions, renaming the element to tvfull_text.. no success sad
            • 23184
            • 8 Posts
            The code doesn’t work either by me.

            The object $modx is not declared yet. So, a couple of rows of code are missing. sad
            If someone have a solution, please let me know.

            Thanks in advance,
            PH-MJS
              • 9932
              • 66 Posts
              This is very simple module with Rich editor:

              1. go to Modules/Manage Modules
              2. press "New Module" button
              3. in "module code" field insert this text:
              $textfield = isset($_POST['textfield']) ? $_POST['textfield'] : "";
              if(!empty($textfield)) echo "Your text was: $textfield";
              echo "<form action='".$_SERVER["REQUEST_URI"]."' method=POST>";
              echo "<div><textarea id='textfield' name='textfield' style='width:100%;' onchange='documentDirty=true;'>$textfield</textarea></div>";
              echo "<button type='submit'>Send</button>";
              echo "</form>";
              $event_output = $modx->invokeEvent("OnRichTextEditorRegister");
              if(is_array($event_output)) $editor = $event_output[0];
              else return "";
              $event_output = $modx->invokeEvent("OnRichTextEditorInit", array('editor'=>$editor, 'elements'=>array("textfield")));
              if(is_array($event_output)) $editor_html = implode("",$event_output);
              echo $editor_html;  

              4. press F5 (Ctrl-R) to reload page (or log out/log in)
              5. have fun.
                • 23184
                • 8 Posts
                Hey all,

                I really need TinyMCE and all its features into my module including filebrowser, etc.
                I saw that a lot of topics was started about this but the most are unreplyed.

                So, if someone know it, please let me know. The above examples don’t work for me. I’ve looked in de code of Modx but I found nothing what I can use.

                Thanks in advance,
                PH-MJS