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

    I'm looking to generate a conformation email using Formit (v 2.1.1). As it stands Formit produces an on screen confirmation message but I also want a "thanks" email to be sent.

    AFAIK, the only way to do this is create a custom hook that calls a corresponding chunk. Is this correct? I thought perhaps that there might be a way to set a message in the systems settings and call it in the Formit snippet e.g. [[++confirmation_message]] but I can't see a param for such a function in the Formit docs.

    My PHP isn't great by any stretch of the imigination but I've come up with the following (which is really just a modification of this excellent tutorial - http://cipalabs.com/modx/articles/send-a-confirmation-email-with-formit):

    <?php
    //configuration
    $mailFrom = $modx->getOption('emailsender'); //OR USE YOUR OWN;
    $mailFromName = $modx->getOption('site_name'); //OR USE YOUR OWN;
    $mailSender = $modx->getOption('site_name'); //OR USE YOUR OWN;
    $mailSubject = 'Subject';
    $mailReplyTo = $mailFrom;
    	   
    $message = $modx->getChunk('ConfirmationTpl');
    	   
    $modx->getService('mail', 'mail.modPHPMailer');
    $modx->mail->set(modMail::MAIL_BODY,$message);
    $modx->mail->set(modMail::MAIL_FROM,$mailFrom);
    $modx->mail->set(modMail::MAIL_FROM_NAME,$mailFromName);
    $modx->mail->set(modMail::MAIL_SENDER,$mailSender);
    $modx->mail->set(modMail::MAIL_SUBJECT,$mailSubject);
    $modx->mail->address('to',$mailTo);
    $modx->mail->address('reply-to',$mailReplyTo);
    $modx->mail->setHTML(true);
    	 
    if (!$modx->mail->send()) {
        $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
    return false;
    }
    	 
    $modx->mail->reset();
    	 
    return true;


    As you can see my 'ConfirmationTpl' chunk will simply contain static text, no dynamic placeholders.

    I'm hoping that an experienced eye could look over the above code and see that everything looks correct and that I haven't got anything superfluous in there. All in all, I guess the part of the snippet that is confusing me is the following:

    $modx->getService('mail', 'mail.modPHPMailer');
    $modx->mail->set(modMail::MAIL_BODY,$message);
    $modx->mail->set(modMail::MAIL_FROM,$mailFrom);
    $modx->mail->set(modMail::MAIL_FROM_NAME,$mailFromName);
    $modx->mail->set(modMail::MAIL_SENDER,$mailSender);
    $modx->mail->set(modMail::MAIL_SUBJECT,$mailSubject);
    $modx->mail->address('to',$mailTo);
    $modx->mail->address('reply-to',$mailReplyTo);
    $modx->mail->setHTML(true);


    Any explanation of that would be appreciated.


    Thanks in advance.



    [ed. note: bob-rooney last edited this post 13 years, 8 months ago.]
      • 38705
      • 101 Posts
      Maybe i don't understand your question fully, but you do not have to use any php.
      [[FormIt?
              &emailTpl=`myEmailChunk`
      	&emailTo=`[email protected]`
      	&emailFrom=`[email protected]`
      	&emailSubject=`The subject of the email`
      	&redirectTo=`47`
      ]]
      

      the &emailTpl, myEmailChunk, contains the text you want to email.
      The filled in fields can be echoed by using their placeholders like [[+fieldname]]
      The &redirectTo is the ID of the resource you redirect to when the form is sent. Your Thank You page.
        Addict since 2012....
        • 42465
        • 33 Posts
        That's not quite what I was looking for. As it stands &emailTpl is sending a report to me detailing all the form fields that have been filled out. What I want (or what has been requested of me) is that the not only does the person filling out the form see an on screen "thanks" message, they should also get a similar message delivered to their inbox.

        Right now the snippet calls the following:

        [[!FormIt?
           &hooks=`spam,email,redirect,myhook`
           &emailTpl=`reportTpl`
           &emailTo=`[email protected]`
           &emailSubject=`blah`	
           &emailFrom=`[email protected]]`   
           &emailFromName=`[[+name]]`		
           &redirectTo=`[[*id]]`
           &redirectParams=`{"success":"1"}`
           &submitVar=`competition_form`	
           &validate=`name:required,
        	      surname:required,
        	      email:email:required'
        
        ]]


        I have the the form wrapped in code that says - if not successful the show form else show chunk that contains a "thanks" message.

        I had created the hook (called "myhook" in the example) as outlined in my original post and stuck it in the &hooks but this hasn't worked. But I can't say why.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Can you just use a CC for that?

          &emailTpl=`CentralizedDebtObligationEmailTpl`
          &emailSubject=`Some Sucker Bought Another CDO`
          &emailTo=`[email protected]`
          &emailCC=`[email protected]`
          &emailBCC=`[email protected]`
          &emailBCCName=`CDO Fraud Informant`
            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
            • 10208 ☆ A M B ☆
            • 1,780 Posts
            I think maybe Susan might have overdosed on cheese... huh

            Insofar as sending an email to the subscriber after filling out the form, use the formIt hook:

            formItAutoResponder

            and set the parameter with a new email chunk containing your placehoders just like in your regular email chunk.

            &fiarTpl=`yourEmailChunkFIAR`
              Frogabog- MODX Websites in Portland Oregon
              "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
              Having server issues? These guys have MODX Hosting perfected - SkyToaster
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I followed my ages-old practice of copying direct from the rtfm!

              At least now I've learned about this hook. I always thought an auto-responder was something you used if you were on vacation or something. It never occurred to me that it could be used as a simple "send-a-copy-to-the-submitter" feature.

              Hmmm... cheese. I wasn't going to go out today, the weather is dreadful, but for cheese? I think I'll make a dash to the store.
                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
                • 10208 ☆ A M B ☆
                • 1,780 Posts
                Can't eat without cheese around here either. :~}

                That hook info is in the rtfm, pretty sure. I just discovered and used it for the first time it last month. Works nicely.
                  Frogabog- MODX Websites in Portland Oregon
                  "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                  Having server issues? These guys have MODX Hosting perfected - SkyToaster
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Yes, it's there... I never looked at it before though. Just goes to show I need to spend more time r-ing tfm.

                  Cheese is very expensive here; back in '98 when I was quitting my last "metapelet" (au pair) job for a stupid woman with triplets (I could write a book about that first year here) who had run out of money to pay, she tried to get me to stay for next to nothing, telling me I wouldn't be able to afford to eat cheese if I left the live-in position. So I make it a point to eat pretty much all the cheese I want, just as a matter of principle. She refused to pay me for the last two weeks she owed me to boot! I was going into a high-tech job where I eventually ended up making five times as much, so it wasn't worth the time and effort to take it to court.
                    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
                    • 10208 ☆ A M B ☆
                    • 1,780 Posts
                    Quote from: sottwell at Jan 07, 2013, 07:17 AM
                    Yes, it's there... I never looked at it before though. Just goes to show I need to spend more time r-ing tfm.

                    Cheese is very expensive here; back in '98 when I was quitting my last "metapelet" (au pair) job for a stupid woman with triplets (I could write a book about that first year here) who had run out of money to pay, she tried to get me to stay for next to nothing, telling me I wouldn't be able to afford to eat cheese if I left the live-in position. So I make it a point to eat pretty much all the cheese I want, just as a matter of principle. She refused to pay me for the last two weeks she owed me to boot! I was going into a high-tech job where I eventually ended up making five times as much, so it wasn't worth the time and effort to take it to court.

                    Threats against one's life are one thing, but that's one down low and dirty threat. I would have stolen all her cheese on the last day.

                    I tried the nanny thing once in '88, even moved across the states to NY for this "awesome" opportunity... I landed in insanity land where 18mo old's weren't allowed to touch their own food, 5yo girls were allowed to dress themselves but 6yo boys required hands on assistance. All in disregard for the child's actual abilities. Oh, and they gave me the chicken pox, which at 17yo freakin HURT! One week, and I was out of there. Seems those who hire people to look after their kids often have some kind of crazy going on.

                    If we ever get the chance to meet, I'll bring some Tillamook for you :~}
                      Frogabog- MODX Websites in Portland Oregon
                      "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                      Having server issues? These guys have MODX Hosting perfected - SkyToaster
                      • 3866 ☆ A M B ☆
                      • 350 Posts
                      You might also like to look at FormItBuilder, I used this recently and found it a really neat way to build forms as well as have them processed using Formit and all the usual hooks including setting auto responders. The documentation is pretty detailed but the examples that are included with the package will definitely get things going.

                      Find out more about the package http://modx.com/extras/package/formitbuilder
                      And full documentation http://modxrevo.datawebnet.com.au/
                      And the bit about auto responders here http://modxrevo.datawebnet.com.au/autoresponders

                      FormItBuilder can also record form data into a database - although I haven't tried this one yet! wink
                        Helen Warner
                        Number one pixel!
                        Proud to be linked with MODX at Crimson Pixel