We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37330
    • 9 Posts
    I've got a really slick custom Blog module I'm hoping to release to the community, with one issue - when my form content gets posted all of the html tags are being stripped from my rich text <textarea> field.

    I've looked through the module processor (/manager/processors/execute_module.processor.php) which it hits before running the module itself and don't see anything there that would strip the tags out of my $_POSTed value.

    Just to contrast, I ran a test outside of the module and my the html tags came across in my $_POST value, so I'm thinking it has to be something to do with running inside the module....

    Would love some help on this one.

    Regards,

    T. Carlton
      • 37330
      • 9 Posts
      ---- SOLVED ----

      Well, this isn't the first time I've found an answer to my own problem after posting, but hopefully this will help someone else out.

      I output the $_REQUEST array at the very beginning of my module run to see what was being generated from the module that might be messing up my $_POST values, by running:

      print '<pre>';
      print_r($_REQUEST);
      print '</pre>';
      


      nothing fishy going on with what I saw come out the other end... but I left that code outputting values as I ran different methods in my module. What I found was that $_REQUEST held onto my HTML tags from my form submission, but $_POST didn't, so when I did my SQL INSERT statement I had to call my posted form variables by $_REQUEST['variable-name'].

      For those who may not know, $_REQUEST hold the values of $_POST and $_GET (which can be handy when passing variables around between pages sometimes).

      I have no idea why $_REQUEST and $_POST have different values when the form method="post".

      Hope this helps someone, and if anyone knows why this might be happening, I'd love to know.

      T.
        • 36533
        • 65 Posts
        I'm having a similar problem.

        After reading up on this, I assume this happens because of the /manager/includes/protect.inc.php

        However, I have no idea how to do what you are suggesting and am hoping you might realize an easy fix.

        My code:

        <?php
        function CreateBlogPost( &$fields ){
            
            global $modx;
            $values = array();
        	
            $values['pagetitle'] = $modx->db->escape($fields['title']);
            $values['longtitle'] = '';
            $values['description'] = '';
            $values['alias'] = '';
            $values['published'] = 1; //0 - if you want the document to be created unpublished
            $values['parent'] = 47; //id of the container for the the new document
            $values['introtext'] = '';
            $values['content'] = $modx->db->escape($fields['content']);
            $values['template'] = 7; //the template of your new document
            $values['searchable'] = 1;
            $values['cacheable'] = 1;
            $values['createdby'] = 1; //this is not the web user ID. Change it to an existing manager id
            $values['createdon '] = time();
            $values['editedby'] = 1; //this is not the web user ID. Change it to an existing manager id
            $values['editedon '] = time();
            //you can find more document properties by browsing the modx_site_content table
        	
            //insert the new document. In case you need the id of the new document use the  $newId variable
            $newId = $modx->db->insert( $values, $modx->getFullTableName('site_content') );
        	
        	//page specific template variables
        	$tvValues = array();
        	
        	$tvValues['tmplvarid'] = 2;//ID of the TV
        	$tvValues['contentid'] = $newId; //The ID of the DOCUMENT
        	$tvValues['value'] = $modx->db->escape($fields['tags']);
        	$modx->db->insert( $tvValues, $modx->getFullTableName('site_tmplvar_contentvalues') );
            
            //clear the cache. in case you use Ditto to display the new document
            clearCache();
        	
            return true;
        }
        
        function clearCache() {
            include_once "manager/processors/cache_sync.class.processor.php";
            $sync = new synccache();
            $sync->setCachepath("assets/cache/");
            $sync->setReport(false);
            $sync->emptyCache();
        }
        


        My field "content" is a textarea with TinyMCE formatting the input on the front-end by a web user. The problem is, as you ran into as well, that it strips the HTML tags.

        Do you know how I might modify this code snippet to correct this behavior?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Try setting the eForm snippet parameter

          &allowhtml (Optional) Set to 1 to allow user to enter html tags. Defaults to 0
            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