We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20349 ☆ A M B ☆
    • 453 Posts
    I'm trying to implement a simple "one-page" jQuery shop (more like ordering page) to my site... jQuery part is working, but I want that order to be send by email.
    Wanted behavior is:
    1. Click on items to drop them into basket
    2. Press Checkout -> go to a page with summary of order,
    3. ...and under I would like to have a form with some usual fields to populate.
    4. press "SEND" to send an order to email with summary of order.


    Steps 1,2,3 are fine, but I'm stuck on step 3! smiley

    So far I tried this:

    1. Create a snippet (web-order) with following code:
    <?php
    print "<strong>Your order:</strong>:<hr/>";
    
    for($i = 0; $i < count($_POST["id"]); $i++){
    	print $_POST["id"][$i]." - ".$_POST["name"][$i]." - ".$_POST["price"][$i]." - ".$_POST["quantity"][$i]."x<br/>";
    }
    
    print "<br/><strong>Total cost:</strong><hr/> ".$_POST["cost"];
    ?>
    


    2. insert it before eForm snippet (I added &eFormOnBeforeMailSent=`web-order`.).


    I'm stuck here.... Please help!!! smiley
      BASE - Web Design Studio
      MODX Ambassador

      Website
      • 23491 ☆ A M B ☆
      • 1,056 Posts
      You should be able to call your snippet via eForm's runSnippet call, then you'll want to include a function (which I believe accepts &$fields as a parameter / reference). This is what you pass into eFormOnBeforeMailSent, a function name that exists based on the inclusion of the snippet.

      NOTE: runSnippet is NOT required, but can simplify your snippet call syntax

      e.g.
      &runSnippet=`web-order` &eFormOnBeforeMailSent=`emailOrder`


      web-order snippet example w/ eForm function:
      <?php
      function emailOrder( &$fields ){
      
          // Do something with $fields array here...
      
          return true;
      }
      
      return '';
      


      I have not tested this code (going off of memory), but I believe this should get you on the right track... Also, I would be careful about your direct use of $_POST variables like that, if you fail to properly sanitize them you may be vulnerable to unwanted code injections, etc.
        Mike Reid - www.pixelchutes.com
        MODx Ambassador / Contributor
        [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
        ________________________________
        Where every pixel matters.
        • 20349 ☆ A M B ☆
        • 453 Posts
        Thanks for reply... I will try what you suggested.. but be aware I'm not a programer. Im a designer smiley

        I just want to connect eForm ability (on checkout) with this plugin: http://codecanyon.net/item/jquery-plugin-shopping-cart/350282

        Any ideas are welcome smiley
          BASE - Web Design Studio
          MODX Ambassador

          Website
          • 20349 ☆ A M B ☆
          • 453 Posts
          Tried what you suggested and I got this error
          Fatal error: Cannot redeclare emailorder() (previously declared in /home/..../public_html/manager/includes/document.parser.class.inc.php(770) : eval()'d code:2) in /home/..../public_html/manager/includes/document.parser.class.inc.php(770) : eval()'d code on line 15

          I'm obviously doing something wrong here sad
            BASE - Web Design Studio
            MODX Ambassador

            Website
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            When adding functions to eForm, you either put your snippet in the resource before the eForm snippet, or use &runSnippet in the eForm call. You can't do both, or they both try to declare your function.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 23491 ☆ A M B ☆
              • 1,056 Posts
              Quote from: Mproject at Feb 21, 2013, 06:35 AM
              Tried what you suggested and I got this error
              Fatal error: Cannot redeclare emailorder() (previously declared in /home/..../public_html/manager/includes/document.parser.class.inc.php(770) : eval()'d code:2) in /home/..../public_html/manager/includes/document.parser.class.inc.php(770) : eval()'d code on line 15

              I'm obviously doing something wrong here sad

              One additional way to work around this is by the use of function_exists() method... In a few, rare cases, you may find yourself needing multiple eform calls on the page...they may use different templates, but share common snippet logic.

              Doing the following can assist in those situations:

              web-order snippet example w/ eForm function:
              <?php
              if( !function_exists('emailOrder') ){
                  function emailOrder( &$fields ){
                      
                      // Do something with $fields array here...
                      
                      return true;
                  }
              }
              return '';
              
                Mike Reid - www.pixelchutes.com
                MODx Ambassador / Contributor
                [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                ________________________________
                Where every pixel matters.
                • 20349 ☆ A M B ☆
                • 453 Posts
                If I write the snippet like this:
                <?php
                print "<strong>Your order:</strong>:<hr/>";
                 
                for($i = 0; $i < count($_POST["id"]); $i++){
                    print $_POST["id"][$i]." - ".$_POST["name"][$i]." - ".$_POST["price"][$i]." - ".$_POST["quantity"][$i]."x<br/>";
                }
                 
                print "<br/><strong>Total cost:</strong><hr/> ".$_POST["cost"];
                ?>

                ..it outputs the message before the eForm call.

                If I try to do it like this:
                <?php
                if( !function_exists('emailOrder') ){
                    function emailOrder( &$fields ){
                         
                	// Do something with $fields array here...
                	echo "<strong>Your order:</strong>:<hr/>";
                	
                	for($i = 0; $i < count($_POST["id"]); $i++){
                	echo $_POST["id"][$i]." - ".$_POST["name"][$i]." - ".$_POST["price"][$i]." - ".$_POST["quantity"][$i]."x<br/>";
                	}
                	
                	echo "<br/><strong>Total cost:</strong><hr/> ".$_POST["cost"];
                	
                         
                        return true;
                    }
                }
                return '';
                ?>
                

                ..it does nothing. Nothing show up.

                Maybe I'm doing some syntax errors?



                P.S. my eForm call looks like this:

                [!eForm? &runSnippet=`web-order` &eFormOnBeforeMailSent=`emailOrder` &formid=`orderForm`  .......!] 

                [ed. note: Mproject last edited this post 13 years, 7 months ago.]
                  BASE - Web Design Studio
                  MODX Ambassador

                  Website
                  • 20349 ☆ A M B ☆
                  • 453 Posts
                  UPDATE:

                  I got the text to appear before the form using this:

                  Snippet (web-order)
                  <?php
                  //functions for eForm events
                  function emailOrder(&$fields) {
                  
                  	echo "<strong>Your order:</strong>:<hr/>";
                  	
                  	for($i = 0; $i < count($_POST["id"]); $i++){
                  	echo $_POST["id"][$i]." - ".$_POST["name"][$i]." - ".$_POST["price"][$i]." - ".$_POST["quantity"][$i]."x<br/>";
                  	}
                  	
                  	echo "<br/><strong>Total cost:</strong><hr/> ".$_POST["cost"];
                  }
                  return;
                  ?>


                  eForm call (using &eformOnBeforeFormParse)
                  [!eForm? &runSnippet=`web-order` &eformOnBeforeFormParse=`emailOrder` &formid=`narudzbaForma` &subject=`[+subject+]` &to=`[(emailsender)]` etc....!]


                  ..but now there is another problem smiley
                  In email report I don't see the upper text (order summary).
                  Am I missing something in my report TPL ?

                  P.S. Does anyone have link to some decent eForm tutorial or something on eForm functions?
                    BASE - Web Design Studio
                    MODX Ambassador

                    Website