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

    I have a form with an implementation of eform2db which creates a new (unpublished) page whenever the form is summitted. So far so good.

    But now I would like to use some of the submitted form data to also populate TVs on the newly-created page, but to do this I obviously need the docid of said page. Any ideas how I would go about doing this?

    All suggestions mightily appreciated.


    function eForm2db( &$fields )
        {
            
            // Bring needed resources into scope
            global $modx, $table_prefix;
     
            // Init our array
            $dbTable = array(); // key = DB Column; Value = Insert/Update value
     
            // Insert field/value pairs to insert/update in our table
            //$dbTable[name] = $fields[first_name].' '.$fields[last_name]; // Merge two form fields together
    
    $dbTable[type] = "document";
    $dbTable[contentType] = "text/html";
    $dbTable[pagetitle] = $modx->db->escape($fields[pagetitle]);
    $dbTable[longtitle] = $modx->db->escape($fields[longtitle]);
    $dbTable[description] = "";
    $dbTable[parent] = "3";
    $dbTable[published] = "0";
    $dbTable[introtext] = $modx->db->escape($fields[introtext]);
    $dbTable[content] = $modx->db->escape($fields[content]);
    $dbTable[richtext] = "1";
    $dbTable[template] = "4";
    $dbTable[menuindex] = "0";
    $dbTable[searchable] = "1";
    $dbTable[cacheable] = "0";
    $dbTable[createdby] = "2";
    $dbTable[createdon] = time();
    $dbTable[deleted] = "0";
    
     
    // Run the db insert query
            $dbQuery = $modx->db->insert( $dbTable, $table_prefix . 'site_content' );      
     
     // Now let's do the Template Variables
    
            $dbTableTV = array(); // key = DB Column; Value = Insert/Update value
    
    $dbTableTV[value1] = $modx->db->escape($fields[value1]);
    
    //ERRR...how to get the ID of the doc??
                     
            // Run the db insert query
            $dbQueryTV = $modx->db->insert( $dbTableTV, $table_prefix . 'site_tmplvar_contentvalues' );      
    
     
    }
    
        // Return empty string
        return '';
    
    
      • 16278
      • 928 Posts
      Doesn't $modx->db->insert() return the ID as $dbQuery?
      :) KP
        • 44362
        • 2 Posts
        Thanks.

        Actually solved it using $modx->db->getInsertId();