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

    I'm using MODX 2.2.10 with FormIt 2.2.0.

    In my site i have created a form with FormIt and configured that the user who fills out the form gets a confirmation mail:

    [[!FormIt?
       &hooks=`spam,email,redirect`
       &emailTpl=`Confirmation-chunk`
       &emailSubject=`Confirmation` 
       &emailCC=`[[+email]]` 
       &emailTo=`[email protected]`
       &redirectTo=`3`
       &validate=`name:required,
          email:email:required`
    ]]
    


    Is it possible to define another chunk/template for the email that is send to the CC-User, like an &emailCcTpl?

    Cheers in advance!

      • 35756
      • 166 Posts
      This helped me to create a confrmation mail for the submitter:

      http://cipalabs.com/modx/articles/send-a-confirmation-email-with-formit

      But I'm still struggling with radiobuttons and getting their value included into the confirmation-mail!

      This is my FormIt-Call

      [[!FormIt?
      &customValidators=`Check-Name,Check-Email,Telefon`
      &store=`1`
      &hooks=`spam,email,customhook,redirect`
      &emailTpl=`mail-chunk`
      &emailTo=`[email protected]`
      &emailFromName=`[[+name]]`
      &emailSubject=`Neue Kurs-Anmeldungen`
      &redirectTo=`3`
      &validate=`name:Check-Name:required,
      telefon:Check-Telefon:required,
      email:Check-Email:required,
      colors:required`]] 


      This is my html-form:

      <form action="[[~[[*id]]]]" method="post" class="form">
      
      <input type="hidden" name="colors" value="[[+fi.colors]]" />
      <ul>
      <li>
      <input type="checkbox" name="colors[]" value="Kurs1 ########" />
      </li>
      <li>
      <input type="checkbox" name="colors[]" value="Kurs2 ########" />
      </li>
      <li>
      <input type="checkbox" name="colors[]" value="Kurs3 ########" />
      </li>
      </ul>
      
      <div class="clear"> </div>
       
      <input type="text" name="name" id="name" value="[[!+fi.name:empty=`Dein Name`]]" [[!+fi.error.name:notempty=`class="error"`]] onfocus="this.value='';" onblur="if (this.value=='') this.value='Dein Name';" /><br />
      <input type="text" name="telefon" id="telefon" value="[[!+fi.telefon:empty=`Deine Telefonnummer`]]" [[!+fi.error.telefon:notempty=`class="error"`]] onfocus="this.value='';" onblur="if (this.value=='') this.value='Deine Telefonnummer';" /><br />
      <input type="text" name="email" id="email" value="[[!+fi.email:empty=`Deine Email-Adresse`]]" [[!+fi.error.email:notempty=`class="error"`]] onfocus="this.value='';" onblur="if (this.value=='') this.value='Deine Email-Adresse';" /><br class="clear" />
       
          <div class="form-buttons">
              <input type="submit" value="> FÜR AUSGEWÄHLTE KURSE ANMELDEN" />
          </div>
      </form>


      This is the normal mail-chunk send to the admin:

      Name: [[+name]]<br />
      Email: [[+email]]<br /><br />
      
      Die Anmeldung erfolgt für folgende Kurse:<br /><br />
      
      [[+colors]]


      By using this the values of the selected checkboxes get transmitted by the placeholder [[+colors]], when all checkboxes got checked and the form submitted - nearly like i want it to be; i only don't know how i separate each value with a linebreak instead of the "########" i added?

      This is how the placeholder [[+colors]] get transmitted in the mail-chunk:
      Kurs1 ######## Kurs2 ######## Kurs3 ######## 

      I want these values separated by a linebreak or inside a html-list...


      But my bigger problem is when I use this for the Confirmation-Mail-Tpl, the "placeholder" [[+colors]] is empty, regardless how many checkboxes have been checked before:

      Hallo [[+name]]!<br /><br />
      
      Wir haben Deine Kurs-Anmeldungen erhalten.<br /><br />
      
      Email: [[+email]]<br /><br />
      
      Die Anmeldung erfolgt für folgende Kurse:<br /><br />
      
      [[+colors]]
      



      Here is the customhook-snippet:

      <?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 = 'MY SUBJECT';
      $mailReplyTo = $mailFrom;
       
      //get fields values so they can be replaced in the email chunk
      $confirmationFields['name'] = $scriptProperties['fields']['name'];
      $confirmationFields['email'] = $scriptProperties['fields']['email'];
      $confirmationFields['colors'] = $scriptProperties['fields']['colors'];
      
      //get user's email
      $mailTo= $scriptProperties['fields']['email'];
         
      $text = $modx->getChunk('ConfirmationTpl', $confirmationFields);
         
      $modx->getService('mail', 'mail.modPHPMailer');
      $modx->mail->set(modMail::MAIL_BODY,$text);
      $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);
      $modx->mail->reset();
      return true;
      }
       
      $modx->mail->reset();
       
      return true;


      Additional info to the customhook-snippet:

      I had to edit this original part:

      if (!$modx->mail->send()) {
          $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
      }


      to this

      if (!$modx->mail->send()) {
          $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
      $modx->mail->reset();
      return true;
      }


      because otherwise the form doesn't redirect on submit. There's somewhere an error inside this if-condition i couldn't sort out. But as the mails get sent I chose this "workaround" to get the redirection-hook running as desired...

      So can anybody tell me how i get a linebreak for each [[+colors]]-placeholder? And how do i get this placeholder filled and the values transmitted in the Confirmation-Mail too?
      • You may need to use the &store property to get it to pass the fields into the post-hook.
          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
          • 35756
          • 166 Posts
          Hi sottwell and thanks for you reply!

          But as you can see I already use the "&store=`1`" in my formit call.
            • 35756
            • 166 Posts
            first problem soveld by adding this to my FormIt-call:

            &emailMultiSeparator=`<br />`


            Second issue is still existent...

            I tried to use the following by changing line 12 in the customhook-snippet, but still no output in the confirmation mail:

            $confirmationFields['colors[]'] = $scriptProperties['fields']['colors'];


            $confirmationFields['colors'] = $scriptProperties['fields']['colors[]'];

            $confirmationFields['colors[]'] = $scriptProperties['fields']['colors[]'];


            I also did try this variant in the Confirmation-Mail-Tpl:

            [[+colors[]]]


            Still not working...
              • 4172
              • 5,888 Posts
              try:

              //get fields values so they can be replaced in the email chunk
              $confirmationFields['name'] = $scriptProperties['fields']['name'];
              $confirmationFields['email'] = $scriptProperties['fields']['email'];
              $colors = $scriptProperties['fields']['colors'];
              $confirmationFields['colors'] = is_array($colors) ? implode(',',$colors) : $colors; 
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 35756
                • 166 Posts
                Hi Bruno!

                And thanks a lot, this works like it should! You saved me (again)!

                Makes sense, because ['colors'] is an array, the other fields are simple text-inputs. I searched for the original email-function FormIt uses to get a hint, but I had no luck so far by doing that.

                Glad this works, thank you very much again!