We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2611
    • 394 Posts
    When I'm adding a custom field through a plugin, the response suddenly fails when saving a resource:

    {"success":true,"message":"","total":0,"data":[],"object":{"id":96,"type":"document","contentType":"text\/html","alias":"blog","published":true,"pub_date":0,"unpub_date":0,"parent":0,"isfolder":true,"richtext":true,"template":38,"menuindex":3,"searchable":true,"cacheable":true,"createdby":1,"createdon":"2014-10-14 18:28:48","editedby":1,"editedon":"2014-10-16 11:14:54","deleted":false,"deletedon":0,"deletedby":0,"publishedon":"2014-10-14 18:32:00","publishedby":1,"donthit":false,"privateweb":false,"privatemgr":false,"content_dispo":0,"hidemenu":false,"class_key":"modDocument","context_key":"web","content_type":1,"uri":"blog\/","uri_override":0,"hide_children_in_tree":0,"show_in_tree":1,"create-resource-token":"123","reloaded":"0","parent-original":"0","parent-cmb":"","syncsite":1,"fltr_resource":"96","fltr_user":"","fltr_from":"","fltr_context_key":"","class":"","fltr_until":"","ext-comp-1058":"20","content_column_1":"<p>Test<\/p>","content_column_2":"","content_column_3":"","content_column_4":"","action":"resource\/update","resource_groups":"[]","preview_url":"http:\/\/websiteurl.com\/blog\/"}}</p>

    Check out the content_column_1 value: <p>Test<\/p>

    How can it be half encoded? Doesn't matter how I save it, just doesn't end well...when you look at the end of the JSON response it tries to close the P tag, hence a JS failure. How come? Any pointers?

      Follow me on twitter: @b03tz
      Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
      CodeMaster
      • 2611
      • 394 Posts
      Here's an example field that I'm adding:

      <div class="col-3">
      <div class="x-form-item x-tab-item" tabindex="-1" id="content_column_1">
      <strong style="width:auto;" class="x-form-item-label">Inhoud: kolom 1</strong>
      <div class="x-form-element" style="padding-left:0;">
      <textarea style="width: 100%; height: 60px;" autocomplete="off" id="modx-resource-content_column_1" name="content_column_1" class="x-form-textarea x-form-field modx-richtext" title=""><?php echo $resource->getProperty('content_column_1'); ?></textarea>
      </div>
      <div class="x-form-clear-left"></div>
      </div>
      </div>
        Follow me on twitter: @b03tz
        Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
        CodeMaster
        • 2611
        • 394 Posts
        When I do this in the connector index file:

        $_POST['field'] = rawurlencode($_POST['field']);

        And in my MODX plugin onDocFormSave do:
        $resource->setProperty('field', rawurldecode($_POST['field']));

        Everything is fine smiley

        Why is this?
          Follow me on twitter: @b03tz
          Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
          CodeMaster
          • 2611
          • 394 Posts
          Fixed by using the following 'hack':

          Plugin
          switch ($modx->event->name) {
          	case 'OnInitCulture':
          		foreach($_POST as $key => $value) { 
          			if (stripos($key, 'field_prefix') !== false) {
          				$_POST[$key] = rawurlencode($value);
          				$_REQUEST[$key] = rawurlencode($value);
          			}
          		}
          		break;
          }


          And when saving I decode them back:
          $resource->setProperty('field_prefix_testfield', rawurldecode($value));


          Not very pretty, works perfectly though. Now the JSON response is not messed up anymore...
            Follow me on twitter: @b03tz
            Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
            CodeMaster
            • 18373 ☆ A M B ☆
            • 3,141 Posts
            Have you tried using ExtJS to add the fields instead of directly putting in markup?

            Also, pardon the shameless plug, but if you're looking for multiple columns of content you should definitely check out ContentBlocks.
              Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

              Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
              • 2611
              • 394 Posts
              Hey Mark, I'm well aware of your awesome plugin...but it defeats the purpose of what I'm trying to do smiley

              I've not tried ExtJS, and since I'm following the "offical" docs I expect this to work. It's fixed for now, but it's very weird behaviour, the </p> tag is a well known bug for Ext..but my fix doesn't make sence in that use-case scenario.

              Anyway, I'm done for now, thanks for your help!
                Follow me on twitter: @b03tz
                Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
                CodeMaster