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

    First, in my template I have a Ditto call :
    [+phx:mo=`webGroup`:then=`[[Ditto? &startID=`[*id*]` &level=`1` &tpl=`completeChunk` &orderBy=`id DESC`]]`:else=`[[Ditto? &startID=`[*id*]` &level=`1` &tpl=`nonConnectedChunk` &orderBy=`id DESC`]]`+]


    Then, in the completeChunk :
    <div class="item" id="item[+id+]">
    
    	<!-- (...) anything -->
    
    	[!sendToDb!]
    	[!eForm? &noemail=`true` &formid=`saveItem` &eFormOnBeforeMailSent=`sendToDb` &tpl=`saveItem`!]
    
    </div>


    The saveItem chunk looks like that :
        <form method="post" action="[~[*id*]~]" id="saveItem" name="saveItem"> <!-- problem : the id is not unique in the page -->
    
        <fieldset>
    
        <label for="saveItem"></label>
        <p><input name="iditem" id="iditem" class="text" type="text" value="[*id*]"/></p> <!-- displays the parent's id :( -->
         
        <p><input type="submit" name="contact" id="cfContact" class="button" value="Send"/></p>
        </fieldset>
        </form>


    And finally, here is the sendToDb snippet :
    <?php
    if (!function_exists('sendToDb')) {
        function sendToDb( &$fields ){
            global $modx;
    
            // Init our array
            $dbTable = array();
    
            // gets the parent's id...
            //$dbTable['iditem'] = $modx->documentIdentifier; 
            //$dbTable['iditem'] = $modx->db->escape($fields['iditem']);
    
            // this works perfectly
            $dbTable['idclient'] = $modx->getLoginUserName();
    
            // Run the db insert query
            $dbQuery = $modx->db->insert($dbTable, 'myDB');
            return true;
        }
    }
    ?>
      • 3749
      • 24,544 Posts
      Try this:

      $dbTable['iditem'] = $modx->db->escapt($_POST['iditem']); 
      



      Remove this inside the form -- you shouldn't need it and it makes the HTML invalid.

      id='saveitem'



      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 40469
        • 33 Posts
        $_POST['iditem'] is also filled with the id of the parent (which is the page where all the items are displayed).
        And if I have X items in the page, it creates X lines instead of one. [ed. note: youfff last edited this post 14 years, 3 months ago.]
          • 3749
          • 24,544 Posts
          Switch to this in the saveItem chunk:

          value="[+id+]"



          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 40469
            • 33 Posts
            Already tried this, it displays nuts. This is actually the main part of my problem.
            Sure, I can display this value in the completeChunk, but not in the saveItem chunk.
              • 3749
              • 24,544 Posts
              Are you getting the saveItem chunk with Ditto? Ditto should be replacing that placeholder with the ID of the page being retrieved. The saveItem chunk should be one of your Ditto Tpl chunks in order to have the placeholders populated correctly.


              ------------------------------------------------------------------------------------------
              PLEASE, PLEASE specify the version of MODX you are using.
              MODX info for everyone: http://bobsguides.com/modx.html

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 40469
                • 33 Posts
                I'm getting the saveItem chunk as it is the eForm tpl :
                [!eForm? &noemail=`true` &formid=`saveItem` &eFormOnBeforeMailSent=`sendToDb` &tpl=`saveItem`!]
                  • 3749
                  • 24,544 Posts
                  I don't think that can work. eForm is not going to populate the id placeholder correctly.

                  You may be able to put the eForm tag in the Ditto Tpl chunk.

                  I think Ditto also has a &ph option, which would put the Ditto output in a placeholder which could then go in the eForm Tpl chunk.

                  I'm not sure the Evolution parsing order will support either method, but it might. If not, you might be looking at a custom snippet to do it all.


                  ------------------------------------------------------------------------------------------
                  PLEASE, PLEASE specify the version of MODX you are using.
                  MODX info for everyone: http://bobsguides.com/modx.html
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 40469
                    • 33 Posts
                    Problem solved !
                    I used an Ajax request to save my form's ID into the database, and it works great.
                    eForm was actually a wrong way.

                    Thanks so much to everyone, I really appreciate your help.