We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38783
    • 571 Posts
    I am trying to create a form which triggers emails to be sent to multiple email addresses, based on users input. I need to use check boxes for the multiple selection.

    I have experimented with the select method of email address selection and this works, but does not provide the user with the opportunity to make multiple selections.

    My form with check boxes does not actually send any emails.

    Which ever method I use, select or check box, my results page contains the correct email addresses, separated by commas, but the emails are never sent.

    Any help gratefully received.

    Thanks

    Andy

    PS: I posted the question in the wrong location before and have moved it to the Revo 2.2 specific forum. Apologies if you have read it before.

    The Form using check boxes - THIS DOES NOT SEND EMAILS BUT DOES RETURN THE CORRECT INFO ON SUCCESS PAGE
    <form action="" method="post">
     
        <label for="name">Name:</label>
     
        <input type="text" name="name" id="name" value="[[!+fi.name]]">
     
        <label for="email">Email</label>
         
        <input type="text" name="email" id="email" value="[[!+fi.email]]">
     
    
    <label>Address Emails To [[!+fi.error.addressTo]]</label>
            <input type="hidden" name="addressTo[]" value="" />
            <input type="checkbox" name="addressTo[]" value="[email protected]" [[!+fi.addressTo:FormItIsChecked=`[email protected]`]] > Andy
            <input type="checkbox" name="addressTo[]" value="[email protected]" [[!+fi.addressTo:FormItIsChecked=`[email protected]`]] > Info
    <input type="submit" value="Submit">
     
    </form>
    [[!FormIt? &validate=`addressTo:required`
       &store=`1`
       &hooks=`email,redirect`
       &emailFrom=`[email protected]`
       &emailTpl=`myEmailChunk2`
       &emailTo=`[[+addressTo]]`
       &emailSubject=`My First FormIt Form`
       &emailMultiSeparator=`,`
       &redirectTo=`4`
    ]]
    


    The Form using select - THIS DOES SEND EMAILS AND RETURNS THE CORRECT INFO ON SUCCESS PAGE
    <form action="" method="post">
     
        <label for="name">Name:</label>
     
        <input type="text" name="name" id="name" value="[[!+fi.name]]">
     
        <label for="email">Email</label>
         
        <input type="text" name="email" id="email" value="[[!+fi.email]]">
    
    
    <select name="addressTo">
       <option value="[email protected]" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>Andy</option>
       <option value="[email protected]" [[!+fi.addressTo:FormItIsSelected=`[email protected]`]]>Info</option>
    </select>
    
    <input type="submit" value="Submit">
     
    </form>
    [[!FormIt? &validate=`addressTo:required`
    &emailMultiSeparator=`,`
       &store=`1`;
       &hooks=`email,redirect`
       &emailFrom=`[email protected]`
       &emailTpl=`myEmailChunk`
       &emailTo=`[[+addressTo]]`
       &emailSubject=`My First FormIt Form`
       &redirectTo=`4`
    ]]
    


    Success Page - THIS WORKS FOR BOTH THE SELECT AND CHECKBOX PAGES
    [[!FormItRetriever]]
    Hello [[!+fi.name]] thanks for submitting this form. <br />
    An email will be sent to [[!+fi.addressTo]] informing them of your request<br />
      If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

      email: [email protected] | website: https://andytough.com
      • 30585
      • 833 Posts
      An approach will be to append the value of each checked fields into a hidden input and then use that field as a placeholder in your &emailTo property. You can use Jquery's serializeArray() method and join your results by a comma. I'll try to create a working fiddle example of the working Jquery approach. You'd simply have to include that on your page. [ed. note: treigh last edited this post 11 years ago.]
        A MODx Fanatic
        • 30585
        • 833 Posts
        Futher to my previous post, here's a live example of what I had in mind.

        Basically you'd need to create a text field or textarea (I prefer the latter) that will act like a container. Then using Jquery, you'd append this container field with the value of your checked checkboxes. In your Formit call you'd simply use this field's for the emailTo property.

        You'd obviously need to hide your container field so the user doesn't see it. I prefer CSS with a hidden class.

        The script:
           function showValues() {
               var fields = $(":checkbox").serializeArray();
               var tokens = jQuery.map(fields, function(field) {
                       return (field.value) ? (field.value) : null;
                   });
               $("#addressto_all").val(tokens.join(','));
           }
          
          $(":checkbox").click(showValues); 
          showValues();


        The field:
        <textarea cols="50" rows="4" id="addressto_all" name="addressto_all" class="hidden"></textarea> 

        The Fiddle
        http://jsfiddle.net/xunT3/23/

        The Formit call:
        [[!FormIt? &validate=`addressTo:required`
           &store=`1`
           &hooks=`email,redirect`
           &emailFrom=`[email protected]`
           &emailTpl=`myEmailChunk2`
           &emailTo=`[[+addressTo_all]]`
           &emailSubject=`My First FormIt Form`
           &emailMultiSeparator=`,`
           &redirectTo=`4`
        ]]


        I'm not a Jquery expert, but I used a similar solution for a form and it works for me.

        I hope it helps. [ed. note: treigh last edited this post 11 years ago.]
          A MODx Fanatic
          • 38783
          • 571 Posts
          Hello, thank you very much for this. I will give it a go now and let you know how I get on.
            If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

            email: [email protected] | website: https://andytough.com
            • 38783
            • 571 Posts
            I have not been able to get this to work yet and have run out of time today. Will be returning to it early next week. Thanks again for you help. Will let you know if I get it to work.
              If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

              email: [email protected] | website: https://andytough.com