We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36551
    • 416 Posts
    Can someone tell me why this is not working? I copied this right of the docs, pasted into my form and changed the email address.

    [[!FormIt?
    ...
    &emailTo=`[[+addressTo]]`
    ]]
    ...
    <select name="addressTo">
    <option value="[email protected]" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>John</option>
    <option value="[email protected]" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>Jane</option>
    </select>
    This will send the email to whoever is selected in the "addressTo" field.
    Here's my form. This is a stripped down version of a working form on a client site.

    <div>
    [[!FormIt? 
    &hooks=`spam,email,redirect,FormItAutoResponder` 
    &emailTpl=`contact-sendto` 
    &fiarTpl=`contact-cc` 
    &fiar=`Name of Website` 
    &fiarSubject=`subject` 
    &fiarFrom=`[email protected]`
    &fiarFromName=`domain`
    &emailTo=`[[+addressTo]]` 
    &emailFrom=`[email protected]`
    &redirectTo=`8` 
    &emailUseFieldForSubject=`1` 
    ]]
    </div>
    
    <div id="form_container">
      <p>[[!+fi.error_message:notempty=`[[!+fi.error_message]]`]]</p>
      <form class="form" action="[[~[[*id]]]]" method="post">
      <input id="email" type="text" name="email" placeholder="Email" value="[[!+fi.email]]" /> [[!+fi.error.email]<br />
    <select name="addressTo">
       <option value="[email protected]" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>terrybarthdesign</option>
       <option value="[email protected]"  [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>terrybarth</option>
    </select>
    <br />
        <textarea id="text" name="text" rows="7" cols="45">[[!+fi.text]]</textarea> <br />
        [[!+fi.error.text]]
        <div class="form-buttons">
          <input type="submit" value="Submit" />
        </div>
      </form>
    </div><!--form_container-->


    The form redirects to the thank you page, the cc email is being delivered, but the selected address is not being delivered. There are no errors in the Modx log.

    I've tried this on multiple occasions and have never been able to get this to work. Is there a secret handshake for this that I don't know about?
      • 13428 ☆ A M B ☆
      • 1,031 Posts
      Try this:

      &emailTo=`[[!+fi.addressTo]]`


      But it is not a good idea to make the emailTo changeable with a email address in the form code. The form code could be changed on client side and you have a nice spamming form available on your site.

      Better use a custom FormIt hook that sets the address on base of a selected number in the form.
        • 36551
        • 416 Posts
        Jako Thanks

        This produces an error:

        An error occurred while trying to send the email. You must provide at least one recipient email address.


        If this is not a secure method, perhaps it shouldn't be cited as an example?

        I don't know how to write a snippet for this. I've seen several in the forums, but it wasn't clear if any of them worked, several examples were reported to not work.

        Do you have one?

        Perhaps a a working example snippet could be put on the documentation page?
          • 36551
          • 416 Posts
          I've attempted to setup several of the suggested snippets from the forums, but have not been able to get any of them working.

          Can someone help me get this working? I have a client waiting for this. I can pay for your time.
            • 17301
            • 932 Posts
            I think you're missing

            <select name="addressTo" value="[[!+fi.addressTo]]">


            (In addition to Jako's suggestion)
              ■ email: [email protected] | ■ website: https://alienbuild.uk

              The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
              • 36551
              • 416 Posts
              LK, Thanks

              I've tried several of variations on this. My latest version includes these:

              &emailTo=`[[!+fi.location]]` 
              
              
              <select name="location" value="[[!+fi.location]]" id="location" >
              
                  <option value="[email protected]" [[!+fi.location:is=`terrybarthdesign@gmail`:then=`selected`]]>Location 1</option>
                  <option value="[email protected]" [[!+fi.location:is=`terrybarth@terrybarth`:then=`selected`]]>Location 2</option>
              
              </select>

              Still getting this error:
              An error occurred while trying to send the email. You must provide at least one recipient email address.
                • 17301
                • 932 Posts
                I've just setup a dummy page to test it myself and it works fine using the code below:


                [[!FormIt? 
                &hooks=`email` 
                &emailTpl=`contact-sendto` 
                &emailTo=`[[+addressTo]]`
                ]]
                
                
                <p>[[!+fi.error_message:notempty=`[[!+fi.error_message]]`]]</p>
                
                <form class="form" action="[[~[[*id]]]]" method="post">
                  <input id="email" type="text" name="email" placeholder="Email" value="[[!+fi.email]]" />
                
                  <select name="addressTo">
                  <option value="[email protected]" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>Ymail</option>
                   <option value="[email protected]" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>Gmail</option>
                 </select>
                
                 <textarea id="text" name="text" rows="7" cols="45">[[!+fi.text]]</textarea>
                
                
                 <input type="submit" value="Submit" />
                
                </form>
                


                Test it yourself first as it is above (but with your emails) and then build outwards to how you want it.

                  ■ email: [email protected] | ■ website: https://alienbuild.uk

                  The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
                  • 36551
                  • 416 Posts
                  Progress. This works on my own test site, but when I copy it to my client site the form does not send.

                  I don't think it's an issue with the dynamic address, because if I replace the placeholder in the emailTo field with my email address the form still doesn't send.

                  So there's something about this site setup that's getting in the way. What's weird is other forms on this site work just fine. Digging in. At least now I have a direction to go.

                  Thank you!
                    • 36551
                    • 416 Posts
                    Well I got this working. Finally. . .

                    I'm not sure what was causing the problem. I went back to a working form on the client site, added the placeholder and the select field and it worked. Seems to me this is exactly how I started this exercise in frustration. smiley

                    In any event, thanks all for your help!