We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3093
    • 45 Posts
    What I'm wanting to do is demonstrated here in the documentation:

    http://rtfm.modx.com/display/ADDON/FormIt.Hooks.email#FormIt.Hooks.email-SpecifyingaDynamicToAddress

    ...and it works great! The problem I have with this solution is it involves hard-coding email addresses into the value attributes of the option tags, where they could potentially be snatched up by e-mail harvesting bots.

    What I want is to be able to do this same thing, but somehow specify the addresses within the FormIt call, or at least somewhere in the server-side scripting where they can't be discovered. Does anyone have any insight into this sort of thing? Ideally the option tags' values would just be numbers (e.g. 1, 2, 3) and these would correspond to the appropriate address.

    Thanks!
      • 30585
      • 833 Posts
      You can store the email addresses on a table on your database and the query the database with AJAX. Here's an example on how to do that: http://www.w3schools.com/php/php_ajax_database.asp

      Obviously you'd need to make the markup adjustments that suit your needs. I'm sorry I couldn't spend more time on this, but hopefully this can help.

      Hopefully someone else has a fully-baked solution that could save you some time.
        A MODx Fanatic
        • 3093
        • 45 Posts
        I know I could use AJAX, but I'd prefer a server-side solution so that the form would still be usable without Javascript. Does anyone else have any ideas for me? Thanks!
          • 46556
          • 4 Posts
          I tried that, too. And I did not get it working. I tried things like
          [[!FormIt?
             &emailTo=`[[+addressTo:customOutputModifier]]`
          ]]
          ...
          <select name="addressTo">
             <option value="1" [[!+fi.addressTo:FormItIsSelected=`1`]]>John</option>
             <option value="2" [[!+fi.addressTo:FormItIsSelected=`2`]]>Jane</option>
          </select>

          and had an output modifier like this:
          switch ($input) {
              case 1: 
                  return '[email protected]';
                  break;
              case 2:
                  return '[email protected]';
                  break;
              default:
                  return '[email protected]';
          }


          But nothing that I tried did work.

          Any different (or working) ideas?
            • 46556
            • 4 Posts
            I found a solution! I added an input field called receiverEmail and added
            display: none;
            for it in my .css-file (it has a double function: serving as anti spam field and for inserting the email adress on the server).

            [[!FormIt? 
                &hooks=`contactAdressInput,email`
                &emailTo=`[[+receiverEmail]]`
                &emailToName=`[[+receiver]]`
                &validate=`receiver:required, receiverEmail:blank`
            ]]
            <select name="receiver">
               <option value="John" [[!+fi.receiver:FormItIsSelected=`John`]]>John</option>
               <option value="Jane" [[!+fi.receiver:FormItIsSelected=`Jane`]]>Jane</option>
            </select>
            <input type="email" name="receiverEmail" />
            


            Now you still need a snippet (I called it contactAdressInput) to insert the email adress:

            switch($hook->getValue('receiver')) {
                case 'John':
                    $hook->setValue('receiverEmail','[email protected]');
                    break;
                case 'Jane':
                    $hook->setValue('receiverEmail','[email protected]');
                    break;
                default:
                    return false;
            }
            return true;
            


            One thing to mention: The documentation states:

            Snippets should return true on success. On failure, the snippet can set error messages in the hook object's errors variable and return false. In either case, hooks listed after the custom hook in the &hooks parameter will not execute.

            So if I understand that right it should not work. But it does. At least for me.