We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12379
    • 460 Posts
    I currently have cart values displaying in eForm’s auto message chunk as follows - would like to find a neater way to insert them using an eFormOnBeforeMailSent function, and then only displaying only the placeholders that contain values (eventually adding table formatting too).

    &automessage chunk:

    <p>Qty    Price($AUD)     Item ID   Product name<br />
    =====================================================================<br />
    [+QUANTITY_1+]    $[+PRICE_1+]       [+ID_1+]   [+NAME_1+]   [+ADDTLINFO_1+]<br />
    [+QUANTITY_2+]    $[+PRICE_2+]       [+ID_2+]   [+NAME_2+]   [+ADDTLINFO_2+]<br />
    [+QUANTITY_3+]    $[+PRICE_3+]       [+ID_3+]   [+NAME_3+]   [+ADDTLINFO_3+]<br />
    [+QUANTITY_4+]    $[+PRICE_4+]       [+ID_4+]   [+NAME_4+]   [+ADDTLINFO_4+]<br />
    [+QUANTITY_5+]    $[+PRICE_5+]       [+ID_5+]   [+NAME_5+]   [+ADDTLINFO_5+]<br />
    [+QUANTITY_6+]    $[+PRICE_6+]       [+ID_6+]   [+NAME_6+]   [+ADDTLINFO_6+]<br />
    [+QUANTITY_7+]    $[+PRICE_7+]       [+ID_7+]   [+NAME_7+]   [+ADDTLINFO_7+]<br />
    [+QUANTITY_8+]    $[+PRICE_8+]       [+ID_8+]   [+NAME_8+]   [+ADDTLINFO_8+]<br />
    [+QUANTITY_9+]    $[+PRICE_9+]       [+ID_9+]   [+NAME_9+]   [+ADDTLINFO_9+]<br />
    [+QUANTITY_10+]    $[+PRICE_10+]       [+ID_10+]   [+NAME_10+]   [+ADDTLINFO_10+]<br />
    [+QUANTITY_11+]    $[+PRICE_11+]       [+ID_11+]   [+NAME_11+]   [+ADDTLINFO_11+]<br />
    <p>Subtotal: [+SUBTOTAL+]<br />
    etc
    
      Mostly harmless.
      • 12379
      • 460 Posts
      Here’s some work I’ve done on its but not working:

      <?php
      
      //  Snippet:   CartSummary eFormOnBeforeMailSent function snippet
      //  Function:  Create cart summary placeholder based on hidden cart fields
      //  Useage:    Add to snippet called before eForm snippet
      
      // The $fields array contains all the form values and other placeholder content with the field names as the key...
      
      
      function createCartSummary( &$fields ){
      
      
      $QUANTITY_1=$fields['QUANTITY_1'];
      $ID_1=$fields['ID_1'];
      $NAME_1=$fields['NAME_1'];
      $ADDTLINFO_1=$fields['ADDTLINFO_1'];
      
      // etc, etc - loop?
      
      
      //Creat placeholder "[+CartSummary+]" for insertion into &automessage chunk... 
      
      $strCartSummary .= "    \$$QUANTITY_1   $ID_1     $NAME_1   $ADDTLINFO_1  \n";
      if( $QUANTITY_2 ) {$strCartSummary .= "$QUANTITY_2    \$$PRICE_2    $ID_2  $NAME_2   $ADDTLINFO_2  \n";}
      if( $QUANTITY_3 ) {$strCartSummary.= "$QUANTITY_3    \$$PRICE_3    $ID_3  $NAME_3   $ADDTLINFO_3  \n";}
      
      //etc, etc  loop?
      
      $fields['CartSummary']=$strCartSummary;
      
      return true;
      
      }
      ?>
        Mostly harmless.
        • 8844
        • 15 Posts
        can u show me all of code for this form .. because i need to do like this ..
        i am junior developer.
        i want to know all of all of .. i mean template,page,chuck and snippet .. write code.
        pls help me ..
        i really don’t know how to do.
          • 12379
          • 460 Posts
          Unfortunately no solution - I went with the less than ideal solution in the first post above.
            Mostly harmless.
            • 12379
            • 460 Posts
            OK, got it, just quickly, I created a snippet "[!eForm_checkout!]" containing:

            <?php
              function checkout ( &$fields )
            	{
            
              global $modx;
            
              // Create cart summary - use Firefox development tools to figure out the being posted by the javascript cart (in caps for this eg)
              $quantity_1=$fields['QUANTITY_1'];
              $price_1=$fields['PRICE_1'];
              $id_1=$fields['ID_1'];
              $name_1=$fields['NAME_1'];
              $addtlinfo_1= htmlentities($fields['ADDTLINFO_1']);
            
              $quantity_2=$fields['QUANTITY_2'];
              $price_2=$fields['PRICE_2'];
              $id_2=$fields['ID_X'];
              $name_2=$fields['NAME_2'];
              $addtlinfo_2=htmlentities($fields['ADDTLINFO_2']);
            
              //repeat for every possible item within cart limit
            
              //Generate table	
              $strCartSummary.= "\n <tr> \n<td style=\"padding: 5px; border: 1px solid #769cc7;\">$quantity_1</td> \n<td style=\"padding: 5px; border: 1px solid #769cc7; text-align: left;\">$name_1 $id_1 $addtlinfo_1</td> \n<td style=\"padding: 5px; border: 1px solid #769cc7; text-align: right;\">\$$price_1</td> \n</tr> ";
            		
              if( $quantity_2 )  {$strCartSummary.= "<tr> \n<td style=\"padding: 5px; border: 1px solid #769cc7;\">$quantity_2</td> \n<td style=\"padding: 5px; border: 1px solid #769cc7; text-align: left;\">$name_2 $id_2 $addtlinfo_2</td> \n<td style=\"padding: 5px; border: 1px solid #769cc7; text-align: right;\">\$$price_2</td> \n</tr> \n";}
            
              // if( $quantity_... repeat for every possible item in the cart
            
              // Add this to the $fields array under the key 'cart-summary'...
              $fields['cart-summary'] = $strCartSummary;
            }
            ?>
            

            On the checkout page the call looks something like this:

            [!eForm_checkout!]
            [!checkRequiredFields!]
            [[validateEFormDate]]
            [!eForm? &eFormOnValidate=`reqFields` &protectSubmit=`1` &eFormOnBeforeMailSent=`checkout` &formid=`payment_form` &to=`[email protected]` &fromname=`Merchant Name` &subject=`Order Confirmation: ((SUBTOTAL)) :: ((name)) :: ((client-order-number))` &jScript=`autofill_js` &automessage=`order_confirmation` &tpl=`payment_form` &report=`checkout_report` &from=`[email protected]` &gotoid=`32` &sendAsHtml=`1`!]


            The javascript cart needs to be called within the eForm form "payment_form" so it’s processed by eForm with the the rest of the payment form.

            Within the "order_confirmation" template chunk, amongst many other things, insert the "cart-summary" field like such:

            <table style="font-size: 12px; border-collapse:collapse; border-spacing: 5px; border: 1px solid#769cc7; width: 100%;" border="0" cellpadding="0" cellspacing="0" >
              <thead style="background-color:#ebf1fb; color: #769cc7;">
               <tr>
                <th style="padding: 5px; border-right: 1px #769cc7 solid;">Qty</th>
                <th style="padding: 5px; border-right: 1px #769cc7 solid;">Product name</th>
                <th>Price($AUD)</th>
               </tr>
              </thead>
              <tbody>
               [+cart-summary+]
               <tr>
                <td colspan="2" style="padding: 5px; border: 1px solid#769cc7; text-align: right;"><b>Subtotal:</b> </td>
                <td style="padding: 5px; text-align: right; border: 1px solid#769cc7;">[+SUBTOTAL+]</td>
               </tr>
               <tr>
                <td colspan="2" style="padding: 5px; border: 1px solid#769cc7; text-align: right;"><b>Delivery charges:</b></td>
                <td style="padding: 5px; text-align: right; border: 1px solid#769cc7;">[+DELIVERY+]</td>
               </tr>
               <tr>
                <td colspan="2" style="padding: 5px; border: 1px solid#769cc7; text-align: right;"><b>TOTAL: </b></td>
                <td style="padding: 5px; text-align: right; border: 1px solid#769cc7;">[+TOTAL+]</td>
               </tr>
              </tbody>
             </table>



              Mostly harmless.