We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18469
    • 7 Posts
    Hi all,

    I am creating custom mailing list manager module. Here I want to include an input field for inserting images. I would like to use MODx’s default file manager for selecting images.

    It should work like when selecting an image which is a TV: just a field and button. When I click on a button the file manager opens and I can select on the server which image I want to insert, then click on the image. After this a new window with the file manager should close and the input field should contain a path to the image which is located somewhere on the server.

    Probably I will need the same functionality for selecting files which are not images - similar to the "File" TV.

    Does anybody know how to do this?

    Thanks a lot!

    Martin
      • 10449
      • 956 Posts
      I would just create a "normal" document, perhaps in a sep. folder, and reference that (parsed) page (id) in the mailing list module. Make sure the template you’re using has only absolute links and file-references though. Doing it like this, you could easily create a newsletter-archive for your regular site-visitors.
        • 18469
        • 7 Posts
        Yes, it is probably the easiest way for a developer. But because of certain reasons I don’t want to use this method.

        There must be a way how to use File manager in modules... huh

        When I include a default RTE to the page in a way described here http://modxcms.com/forums/index.php/topic,6450.msg87778.html#msg87778 and prepend it with some javascript needed by File manager my code looks like this:

        echo '<script type="text/javascript">var modVariables = [];
        function setVariableModified(fieldName){
            var i, isDirty, mv = modVariables;
            for(i=0;i<mv.length;i++){
                if (mv[i]==fieldName) {
                    isDirty=true;
                }
            }
            if (!isDirty) {
                mv[mv.length]=fieldName;
                var f = document.forms[\'mutate\'];
                f.variablesmodified.value=mv.join(",");
            }
        }
        
        function setLink(lId) {
            if (!allowLinkSelection) {
                window.location.href="index.php?a=3&id="+lId;
                return;
            }
            else {  
                    documentDirty=true;
                    document.mutate.ta.value=lId;
            }
        }
        
        // END ADDED BY S BRENNAN
        
        // Added for RTE selection
        function changeRTE(){
            var whichEditor = document.getElementById(\'which_editor\');
            if (whichEditor){
                for (var i=0; i<whichEditor.length; i++){
                    if (whichEditor[i].selected){
                        newEditor = whichEditor[i].value;
                        break;
                    }
                }
            }
            var dropTemplate = document.getElementById(\'template\');
            if (dropTemplate){ 
                for (var i=0; i<dropTemplate.length; i++){
                    if (dropTemplate[i].selected){
                        newTemplate = dropTemplate[i].value;
                        break;
                    }
                 }          
            }
        
            documentDirty=false;
            document.mutate.a.value = 27;
            document.mutate.newtemplate.value = newTemplate;
            document.mutate.which_editor.value = newEditor;
            document.mutate.submit();
        }
        
        function resetParameters() {
            document.mutate.params.value = "";
            lastmod[lastsp]="";
            showParameters();
        }
        </script>';
        
        
        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', '', '', $newsletter);
        
        echo $rte_html;
        echo $editor_html;
        
        // MY MOD: renders input field and button
        echo renderFormElement('image', 'product_main_img', '', '', '', '');


        When clicking on the button, File manager loads properly, I can go through all folders and can see the files. But when trying to insert a file by clicking on it I get the following error in FireBug:

        document.mutate has no properties
        var c = document.mutate[lastImageCtrl];
        index.php (line 171)

        Does anybody know how to correct it so it could insert the image’s address into the input field?
          • 16732
          • 592 Posts
          Hi,

          The form need to have "mutate" for name => <form name="mutate" ..... >
            • 18469
            • 7 Posts
            laurentc,

            thanks a lot for your advice, inserting image into the input field works like a charm now!

            Thanks