We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27449
    • 211 Posts
    Hello,
    I create a module in the modx that work perfectly. But now, I want that when I put there information, these information stay in the database, create one document automaticaly with the information that I put in the module.
    That is possible, when us put information in the modulo create a document in the modx with this information?
      • 4172
      • 5,888 Posts
      You need an field-array for the document-values and for the TV-values, then you can use this function or you can use the docmanager-class:
      http://modxcms.com/Docmanager-881.html
          function insertdoc($doc_array, $tv_array)
          {   global $modx;
              $doctable = $modx->getFullTableName('site_content');
              $tvtable = $modx->getFullTableName('site_tmplvar_contentvalues');
      		//Todo: checkbox to allow invokeevents
              $modx->invokeEvent('OnBeforeDocFormSave', array('mode'=>'new'));
              $modx->db->insert($doc_array, $doctable);
              $id = $modx->db->getInsertId();
              //---------insert TVs----------------------
              foreach ($tv_array as $key=>$value)
              {
                  $insert_array = array (
                  'tmplvarid'=>$key,
                  'value'=>$value,
                  'contentid'=>$id);
                  $modx->db->insert($insert_array, $tvtable);
              }
              $modx->invokeEvent('OnDocFormSave', array('mode'=>'new', 'id'=>$id));								
              return $id;
          }
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 25483
        • 741 Posts
        You could do what Brun17 says, but I think it is better to create a snippet which reads the data from the database and outputs that.

        How would you change or delete the document automaticly when you edit or remove a item in the module?
          with regards,

          Ronald Lokers
          'Front-end developer' @ h2o Media

          • 27449
          • 211 Posts
          Thank you.
          I will go to do, but now I have a problem with the snipped eform huh
          When I introduce checkbox in the form, all the checkboxes appear inside of the border or textarea, I think huh
          The image show you how it is

          I want put the all the checkbox in the same line, How do I do?