We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3232
    • 380 Posts
    I think I am missing something simple...

    I created the following plugin and it does execute only when template 6. I can’t seem to modify the $_POST[’’] information before it is processed.

    $_POST[’template’] does return "6", $_POST[’tvsmall-code’] returns the content of the tv and when I echo the $_POST value after each ereg_replace it does display the correct value. What doesn’t happen is, on next edit the values of the tv haven’t change (this is after I removed the exit line of code.

    What am I missing?

    switch($modx->Event->name){
    case 'OnBeforeDocFormSave' :
    
    	if ($_POST['template'] == 6){
    
    		$string1 = "wmode=\"transparent\"";
    		$string2 = "<param name=\"wmode\" value=\"transparent\" />";
    		$container1 = $_POST['tvsmall-code'];
    		$container2 = $_POST['tvsmall-code'];
    		
    	// Search small code
    		if(strstr($container1,$string1)) {
    			// Do nothing
    		} else {
    			$_POST['tvsmall-code'] = ereg_replace('></embed>', ' wmode="transparent"></embed>', $_POST['tvsmall-code']);
    			//echo '<pre>'.$_POST['tvsmall-code'].'</pre>';
    		}
    	
    		if(strstr($container1,$string2)) {
    			// Do nothing
    		} else {
    			$_POST['tvsmall-code'] = ereg_replace('<embed ', '<param name="wmode" value="transparent" /><embed ', $_POST['tvsmall-code']);
    			//echo '<pre>'.$_POST['tvsmall-code'].'</pre>';
    		}
    		
    	// Search large code
    		if(strstr($container2,$string1)) {
    			// Do nothing
    		} else {
    			$_POST['tvlarge-code'] = ereg_replace('></embed>', ' wmode="transparent"></embed>', $_POST['tvlarge-code']);
    			//echo '<pre>'.$_POST['tvlarge-code'].'</pre>';
    		}
    	
    		if(strstr($container2,$string2)) {
    			// Do nothing
    		} else {
    			$_POST['tvlarge-code'] = ereg_replace('<embed ', '<param name="wmode" value="transparent" /><embed ', $_POST['tvlarge-code']);
    			//echo '<pre>'.$_POST['tvlarge-code'].'</pre>';
    		}
    	}
    //exit;
    break;
    }
      • 3232
      • 380 Posts
      So I have come to the conclusion that the system has already processed the post data by the time the plugin is called which is why modifying the $_POST data is not saving to the database.

      My question is, in what variable is the TV content stored in at the time the plugin is called.

      Any help or direction would greatly be appreciated.

      Thanks
      Brian
        • 23
        • 61 Posts
        Hey Brian

        you are right, seems each external plugin is executed as a last just recognized that because have some similiar trouble, system seem to come first.

        so you could try to read out the template stuff from the site_template... tables, modify and resave them during the onDocFormSave / BeforeSave event
          • 10313
          • 375 Posts
          Hello!

          I believe I want to achieve the same thing like Brian, BUT I’m following a very different approach. The plugin code is

           
          global $content;
          
          $e = &$modx->Event;
          
          if (($e->name == 'OnDocFormRender') && ($content['template'] == 14)) {
          	$output = "<!-- tv2docvar Plugin -->\n";
          	$output .= "<script type=\"text/javascript\">\n";
          	$output .= "function tv2docvar_set(){\r\n" . 
          			"	var source = document.getElementById(\"tvVAStart\");\r\n" . 
          			"	var sourceval = source.value;	// date and time\r\n" . 
          			"	var destination = document.getElementById(\"tvVAEnde\");\r\n" . 
          			"	if(destination.value == \"\"){	//	do not overwrite existing input\r\n" . 
                "   alert('sourceval=' + sourceval);\r\n" .
          			"		destination.value = sourceval;\r\n" . 
                "   alert('destination.value=' + destination.value);\r\n" .
          			"	}\r\n" . 
          			"}\r\n" . 
          			"var myform = document.getElementsByName(\"mutate\")[0];\r\n" . 
          			"myform.addEventListener(\"submit\", tv2docvar_set, false);\r\n" . 
          			"</script>";
          	$output .= "<!-- end tv2docvar Plugin -->\n";
          	$e->output($output);
          }
          


          This plugin inserts javascript when using the given Template. My template is for storing events with start end end date/time. On submission, the plugin gets the input start date and -- if there is no end date given -- sets the end date equal to the start date.

          At least, this is what the plugin is supposed to do. But it does not. As you can see, I have inserted two "alerts" for debugging. In both outputs, I get the correct values. This means: my JS has got the input start date, sets the form field value of end date, reads it for verification and outputs the correct end date wich is now equal to the start date.

          This is, when I use Firefox 3.0.10. If I use Internet Explorer 7, the alerts are not output.

          But, the big problem is: The actual TV is not really set to the given start date. If I reopen the same page for editing, the end date is still empty. In both Fx and IE.

          What can be the problem here?

          Any ideas very much appreciated.
          Thanks in advance
          Martin