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

    I’ve put together some code for a plugin for Revolution, the functional code is about to work but I’m stuck at a two simple points:

    a) How can my plugin send GUI-Elements (html form) to the manager page for the document? Are there special requirements to my form to help integration with MODx (form/field names etc)? The element caught is "OnDocFormRender".

    and b) How can I get back my form-data when the user saves the page? Element caught is "OnDocFormSave".

    Thanks for a hint,

    Henning
      Usually when things have come so far,
      people tend to disappear.

      MODx Revolution Multi-Domain Installation Tutorial | MODxCMS Webentwicklung Frankfurt Rhein-Main
      • 28215
      • 4,149 Posts
      In latest SVN (and upcoming beta5), you can do so via the On*FormRender events. Those events will plug whatever you return straight into the form as HTML.

      For example, this plugin code:
      <?php
      /**
       * Register a form field to forms
       */
      switch ($modx->event->name) {
          case 'OnDocFormPrerender':
              /* if you want to add custom scripts, css, etc, register them here */
              break;
          case 'OnDocFormRender':
              $v = '';
              if (isset($scriptProperties['resource'])) {
                  /* on the update screen, so set the value */
                  $v = 'saved value';
              } else {
                  /* on the create screen, so set the default */
                  $v = 'default value';
              }
              /* now do the HTML */
              $fields = '
      <div class="x-form-item x-tab-item">
          <label class="x-form-item-label">Home</label>
          <div class="x-form-element">
              <input type="text" name="home" value="'.$v.'" class="x-form-text x-form-field" />
          </div>
      </div>
      ';
              $modx->event->output($fields);
      break;
          case 'OnDocFormSave':
              /* do processing logic here. */
              $resource =& $scriptProperties['resource'];
              $resource->set('home',$_POST['home']);
              $resource->save();
              break;
      }
      return;
      


      Note the CSS classes in the field HTML being returned; this is to get the styling to look nice with the ExtJS forms; however, you dont have to do this and can return them however you like.

      This method will work with all the On*FormRender events.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com