On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hi all

    What I am doing is sending an email message using Formit and email snippet, I have a form to write down there multiples emails separated with comma. If I put in the form field one email address it works (the email message is sended) if I put more that one in the field form doesn't work, if I put more that one directly in the formit parameter $emailTo it works.

     
    [[!FormIt? 
    &hooks=`email` 
    &validate=`emails:required`
    &successMessage=`<h2 style="color:green">Your invitation was sent to [[+emails]]!</h2>`
    &emailTpl=`email_event`
    &emailSubject=`Event Invitation - [[+eventName]] - [[!+company]]`
    &emailTo=`[[+emails]]`
     ]]
    
            <form action="[[~[[*id]]]]" method="post" id="eventform" >
            <label>Describe a list of emails separated by comma</label>
            <input type="text" name="emails" id="emails" value=""/>
            <input type="hidden" name="eventName" value=""/>
            <button type="submit" class="btn">Send</button>
    
            </form>


    This question has been answered by yuliyepes. See the first response.

      @yulianita
    • What does successMessage appear as? Does the whole text string output?

      You might try to use emailCC, I don't know why it would work and this doesn't though.

      ...Oh I just found an old thread, this is a bug, and the workaround indeed is to use emailCC, but it might also not accept multiple addresses.

      https://forums.modx.com/thread/101101/formit-emailto-set-through-hook-with-multiple-values-does-not-work

      Looks like it might be better to use another form extra, I asked in that thread what is the best to use. maybe SPform [ed. note: nuan88 last edited this post 3 months ago.]
      • Write a small hook with the following code

        <?php
        $hook->formit->options['emailTo'] = $hook->getValue('emails');
        


        and execute that hook before the email hook.

        The current code of FormIt could just work with [[+email1]],[[+email2]] and the according fields in the form, if I read the current code right. [ed. note: Jako last edited this post 3 months ago.]
        • discuss.answer
          Quote from: Jako at Feb 15, 2019, 10:28 PM
          Write a small hook with the following code

          <!--?php
          $hook--->formit->options['emailTo'] = $hook->getValue('emails');
          


          and execute that hook before the email hook.

          The current code of FormIt could just work with [[+email1]],[[+email2]] and the according fields in the form, if I read the current code right.

          Thank you!!, I don't know why your code doesn't work but it works with this.

          $emails = $hook->getValue('emails');
          $hook->formit->setOption('emailTo', $emails);

            @yulianita