We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6038
    • 228 Posts
    I've created a TV with input type hidden to store a copy of the resource's content just before it is saved. I want to compare the value in this tv with the content after the resource is saved, so I know if the content field has changed or not. (I'm using this with static resources so I can see if a link to a file has changed).

    I save the old content value to the TV 'OnDocFormRender', when the editing page is loaded.
    (The value saves correctly, and can be retrieved at this point, and seen in the DB).
    I want to compare this saved value with the content during the event 'OnDocFormSave'.
    When I get the TV value from the DB at this point, it has gone - it no longer exists.

    As I understand it, hidden type TVs are not even included in the manager pages - so there is not even a value submitted when a resource is saved.

    Am I not understanding how hidden TVs work or is this a bug?
      • 6038
      • 228 Posts
      I should of course have added that I am using Revo 2.2.2, php 5.3.9, apache 2, Linux, mysql5 something (but not that buggy one)
        • 6038
        • 228 Posts
        So here is a shortened version of my code.
        When a resource is edited, we copy the current content into tv3
        When the resource is saved, we compare the content with tv3 to see if there has been a change
        Except, tv3 disappears when I check it, after just having set it.

        What am I doing wrong?

        <?php
        
        switch ($modx->event->name) {
            case 'OnDocFormRender':
        
        			if ( $mode == modSystemEvent::MODE_UPD ) {
        
        				// before the form is edited, we get the current content and copy it to the old content, so we can compare later
        				$content = $resource->get('content');
        				$modx->log(modX::LOG_LEVEL_ERROR, ' [content]: '.$content);
        				$oldcontent = $resource->setTVValue(3, $content);
        				$modx->log(modX::LOG_LEVEL_ERROR, ' [tv3] now set:'.$resource->getTVValue(3));
        					
        			}
        
        		    break;	
            case 'OnBeforeDocFormSave':
        
        			if ( $mode == modSystemEvent::MODE_NEW ) {
        
        			} else if ( $mode == modSystemEvent::MODE_UPD ) {
        
        			}
        
        			break;
        
        	case 'OnDocFormSave':
            
        			if ( $mode == modSystemEvent::MODE_UPD ) {
        
        					$new_content = $resource->get('content');					
        					    $modx->log(modX::LOG_LEVEL_ERROR, ' [content] new:'.$new_content);
        					$old_content = $resource->getTVValue(3);
        					    $modx->log(modX::LOG_LEVEL_ERROR, ' [tv3] old content:'.$old_content);
        
        					if ( $old_content !== $new_content) {
        					    $modx->log(modX::LOG_LEVEL_ERROR, 'content of old and new DO NOT MATCH');
        					} else {
        					    $modx->log(modX::LOG_LEVEL_ERROR, 'content of old and new ARE THE SAME');
        					}
        
        			}
        
        	    	break;
        
        	default:			
        
        }
        
        
        
        return;
          • 6038
          • 228 Posts
          To solve my problem, I'm going to convert the TV to a text input type, and use form customisation to hide it. Boom. No more hidden TVs for me!

          In light of no other responses I'm filing this as a bug.

          http://tracker.modx.com/issues/8081 [ed. note: christianhanvey last edited this post 14 years, 3 months ago.]