We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16861 ☆ A M B ☆
    • 86 Posts
    I have a contact form that will include "areas of interest". Based on the selection, I would like the value be emailed to the appropriate recipient. I am using the following:

    [[!FormIt?
       &hooks=`spam,email,redirect`
       &emailTpl=`MyEmailChunk`
       &emailTo=`[[+addressTo]]`
       &redirectTo=`2`
    ]]
    
    [[!+fi.validation_error_message:notempty=`<p>[[!+fi.validation_error_message]]</p>`]]
     
    <form action="[[~[[*id]]]]" method="post" class="form">
        <input type="hidden" name="nospam:blank" value="[[+fi.nospam]]" />
     
        <label>
            Areas of Interest:
            <select name="addressTo" value="[[!+fi.addressTo]]">
                <option value="">Areas of Interest</option>
                <option value="Interest 1" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>Interest 1</option>
                <option value="Interest 2" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>Interest 2</option>
                <option value="Interest 3" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>Interest 3</option>
            </select>
        </label>
     
        <br class="clear" />
     
        <div class="form-buttons">
            <input type="submit" value="Send Contact Inquiry" />
        </div>
    </form>


    This is not working unless the value is also the email. Is there a way to do this?

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

      Lee Brinckley
      Manassas, VA (Washington DC)
      Twitter - @leebrinckley
      http://www.leebrinckley.com
    • discuss.answer
      • 16861 ☆ A M B ☆
      • 86 Posts
      A huge thanks to Sepiariver and Thijsvandamme for helping me with a solution. The following will send an email depending on the checkbox by using an additional snippet.

      FormIt -
      [[!recipient? &input=[[+area_of_interest]] ]]
      
      [[!FormIt?
         &hooks=`email, redirect`
         &emailTpl=`***`
         &emailTo=`[[+sendTo]]`
         &emailSubject=`***`
         &emailMultiSeparator=`, `
         &redirectTo=`***`
      ]]
      


      Form section -

          <label>
              Area of Interest:
          </label>
      
      <p><label><input type="checkbox" name="area_of_interest[]" value="value 1" [[!+fi.area_of_interest:FormItIsChecked=`Value 1`]] > Value 1</label></p>
      <p><label><input type="checkbox" name="area_of_interest[]" value="Value 2" [[!+fi.area_of_interest:FormItIsChecked=`Value 2`]] > Value 2</label></p>
      <p><label><input type="checkbox" name="area_of_interest[]" value="Value 3" [[!+fi.area_of_interest:FormItIsChecked=`Value 3`]] /> Value 3</label></p>
      


      Snippet called "recipient" -

      <?php
      // Type: Snippet
       
      $recipient = $_POST['area_of_interest'];
       
      if ($recipient == '') { return ''; }
        foreach ($recipient as $key => $value) {
          switch ($value)
          {
            case "Value 1":
              $recipientList[] = 'email1@***.com';
              break;
            case "Value 2":
              $recipientList[] = 'email2@***.com';
              break;
            case "Value 3":
              $recipientList[] = 'email3@***.com';
              break;
            default:
              $recipientList[] = 'email1@***.com';
          }
        }
      
      $modx->setPlaceHolder('sendTo', implode(', ', array_unique($recipientList)));
      


      I hope this is helpful to others.
        Lee Brinckley
        Manassas, VA (Washington DC)
        Twitter - @leebrinckley
        http://www.leebrinckley.com