We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23844
    • 6 Posts
    Iam new to modx.I have an eform with several fields. When i call snippet it is sending mail but the values not saved in database. When the values are stored mail was not sending . I need to work both functionality simultaneously. Anybody please help me...........
      • 18913
      • 654 Posts
      Can you post an example of the code you are trying to get to work?
      Matt
        • 5340
        • 1,624 Posts
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Make sure your snippet’s function ends with
          return true;
            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
            • 23844
            • 6 Posts
            My snippet code is
            function downloadForm( &$fields )
            {
            global $modx;
            $email=$fields[emailaddress];
            $sql = ("select * from `emp_download_form` where `emailaddress` = ’".$fields[’emailaddress’]."’");
            $rs = $modx->db->query($sql);
            $limit = mysql_num_rows($rs);
            if ($limit > 0) {
            $header = "Location: index.php?id=6&msg=Email already exit";
            header($header);


            return true;
            }

            else{

            $date=date(’Y-m-d’);

            $dbTable = array();
            $dbTable[firstname] = $fields[firstname];
            $dbTable[lastname] = $fields[lastname];
            $dbTable[emailaddress] = $fields[emailaddress];
            $dbTable[contactno] = $fields[contactno];
            $dbTable[jobtitle] = $fields[jobtitle];
            $dbTable[companyname] = $fields[companyname];

            $dbTable[industry] = $fields[industry];
            $dbTable[country] = $fields[country1];
            $dbTable[city] = $fields[city];
            $dbTable[state] = $fields[state];
            $dbTable[city] = $fields[city];
            $dbTable[pincode] = $fields[pincode];
            $dbTable[noofemp] = $fields[noofemployee];
            $dbTable[comments] = $fields[comments];
            $dbTable[address1] = $fields[address1];
            $dbTable[address2] = $fields[address2];
            $dbTable[date] =$date;
            // Run the db insert query
            $dbQuery = $modx->db->insert($dbTable, ’emp_download_form’);
            }
            $header = "Location: index.php?id=16";
            header($header);
            return true;
            }
            if($_GET[msg])
            echo "<font color=’#FF0000’>Email Already Exists. Please Try with another Email Address.</font>";
            if($_GET[msg1])
            echo "<font color=’#FF0000’>Please fill the form with alternate email address</font>";
            ?>

            I call snippet like this
            [!downloadForm!][!eForm? &to=’[+emailaddress+],[email protected]’ &formid=`downloadForm` &eFormOnBeforeMailSent=`downloadForm` &tpl=`downloadForm` &report=`downloadFormReport_latest` &subject=`Activation mail` &cc=`1`!]

            Thanks
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              A couple of things. For one, text array keys should be surrounded by quote marks
              $email=$fields[emailaddress];

              as I see you did in other places in the code. It really doesn’t hurt (as far as I know) but it does generate a PHP warning, which may or may not cause a problem depending on your server’s PHP configuration.

              Another point in reference to your snippet call, &cc is not a 1/0 parameter, it takes the email address to which to send the cc.
              &subject=`Activation mail` &cc=`1`!]


              Have you tested the code independently to make sure it runs without errors? A PHP error in the snippet code can cause eForm to fail silently.

                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
                • 23844
                • 6 Posts
                Thanks for your reply,

                After change something in the code simultaneously both functionalities are working, But if the email already exist. I got message "Email already exist" and the datas are not stored in database but the mail is sending. If the email id already exist, i dont want to send email.

                Thanks & Regards
                Premalatha
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Use return false where you want it to stop.
                    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
                    • 23844
                    • 6 Posts
                    After giving return false it is working.

                    Then i have another doubt.
                    Now the activation email link come to my email address.
                    I want to activate it and download the file from that link.
                    how can i do this things.

                    Thanks and Regards
                    Premalatha
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      I would have my report tpl generate the link with a URL that includes a query string with the filename in question; then on the page where the link takes you have a snippet that gets the $_GET from the query string and offers the file for download.
                        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