4

I have another FreeForm question. Below is my Freeform code that is now working, sending emails to different recipients based on the checkboxes selected.

Now I need those selections to appear in the notification email, so the recipients are aware of each other being contacted.

Nosing around it looks like I need a combination of a hidden field and some javascript? Does anyone happen to have that js handy they could post? I'm usually ok to tweak something that's close but don't know enough js to write from scratch.

 {exp:freeform:form
form:id="contact-form"
form_name="contact" 
required="name|email|message|recipient_email"
return="contact/thanks"
recipients="yes"
recipients_limit="11"
recipient_template="to_era" 
recipient1="name|email1@address.com"
recipient2="name|email2@address.com"
recipient3="name|email3@address.com"
recipient4="name|email4@address.com"
recipient5="name|email5@address.com"
recipient6="name|email6@address.com"
recipient6="name|email7@address.com"
recipient8="name|email8@address.com"
recipient9="name|email9@address.com"
recipient10-="name|email10@address.com"
recipient11="name|email11@address.com"
}



<p>
    <label for="name">Name:</label><br />
    <input type="text" id="name" name="name" size="40" maxlength="64" value="" class="textfield" />
  </p>



<p>
    <label for="email">Email:</label><br />
    <input type="text" id="email" name="email" size="40" maxlength="128" value="" class="textfield" />
  </p>

  <p>
    <label for="telephone">Telephone:</label><br />
    <input type="text" id="telephone" name="telephone" size="40" maxlength="16" value="" class="textfield" />
  </p>

  <p>
    <label for="availability">What is the best time for us to reach you?</label><br />
    <input type="text" id="availability" name="availability" size="40" value="" class="textfield" />
  </p>

  <p>
    <label for="message">Message:</label><br />
    <textarea id="message" name="message" rows="18" cols="40" class="textfield"></textarea>
  </p>

  <fieldset id="community_checkboxes">
      <legend>Select each of the communities are you interested in.</legend>

        <p> {!-- ravenna --}
           <input{if segment_2=="ravenna"} checked{/if} type="checkbox" id="{freeform:recipient_value1}" class="community_chbx" value="{freeform:recipient_value1}" name="recipient_email[]">
           <label for="{freeform:recipient_value1}">{freeform:recipient_name1}</label>
        </p>

        <p> 
           <input{if segment_2=="wallingford"} checked{/if} type="checkbox" id="{freeform:recipient_value2}" class="community_chbx" value="{freeform:recipient_value2}" name="recipient_email[]">
           <label for="{freeform:recipient_value2}">{freeform:recipient_name2}</label>
        </p>

          <p> {!--lakeshore--}
           <input{if segment_2=="north-seattle"} checked{/if} type="checkbox" id="{freeform:recipient_value3}" class="community_chbx" value="{freeform:recipient_value3}" name="recipient_email[]">
           <label for="{freeform:recipient_value3}">{freeform:recipient_name3}</label>
        </p>

        <p> {!-- broadview --}
           <input{if segment_2=="mercer-island"} checked{/if} type="checkbox" id="{freeform:recipient_value4}" class="community_chbx" value="{freeform:recipient_value4}" name="recipient_email[]">
           <label for="{freeform:recipient_value4}">{freeform:recipient_name4}</label>
        </p>

        <p> {!--wallingford --}
           <input{if segment_2=="lakeshore"} checked{/if} type="checkbox" id="{freeform:recipient_value5}" class="community_chbx" value="{freeform:recipient_value5}" name="recipient_email[]">
           <label for="{freeform:recipient_value5}">{freeform:recipient_name5}</label>
        </p>

        <p> {!-- mercer-island --}
           <input{if segment_2=="issaquah"} checked{/if} type="checkbox" id="{freeform:recipient_value6}" class="community_chbx" value="{freeform:recipient_value6}" name="recipient_email[]">
           <label for="{freeform:recipient_value6}">{freeform:recipient_name6}</label>
        </p>

        <p> {!--issaquah --}
           <input{if segment_2=="broadview"} checked{/if} type="checkbox" id="{freeform:recipient_value7}" class="community_chbx" value="{freeform:recipient_value7}" name="recipient_email[]">
           <label for="{freeform:recipient_value7}">{freeform:recipient_name7}</label>
        </p>

        <p> {!--bellevue --}
           <input{if segment_2=="bellevue"} checked{/if} type="checkbox" id="{freeform:recipient_value8}" class="community_chbx" value="{freeform:recipient_value8}" name="recipient_email[]">
           <label for="{freeform:recipient_value8}">{freeform:recipient_name8}</label>
        </p>

    <p> 
           <input type="checkbox" id="{freeform:recipient_value10}" class="community_chbx" value="{freeform:recipient_value10}" name="recipient_email[]">
           <label for="{freeform:recipient_value10}">{freeform:recipient_name10}</label>
        </p>        

        <p> 
           <input{if segment_2==""} checked{/if} type="checkbox" id="{freeform:recipient_value9}" class="community_chbx" value="{freeform:recipient_value9}" name="recipient_email[]">
           <label for="{freeform:recipient_value9}">{freeform:recipient_name9}</label>
        </p>



  </fieldset>

  <p><input id="button_submit" name="submit" type='submit' value='Submit Form' /></p>
{/exp:freeform:form}  
4

You could have a text field named 'chosen_recipients and use a jQuery listener to wait for click of the checkboxes and concat the name results in the hidden field.

The hidden field could then be output as a normal field in the notification.

    <input name="chosen_recipients" type="hidden" />
    <script type="text/javascript">
            jQuery(function($){
                    var $chosenRecipients   = $('[name="chosen_recipients"]');
                    var $recipientChecks    = $('[name^="recipient_email"]');

                    $recipientChecks.click(function(){
                            //force this check to wait until checkbox state is resolved
                            //works weirdly in some browsers without this
                            setTimeout(function(){
                                    $chosenRecipients.val('');
                                    var newVal = [];
                                    $recipientChecks.each(function(){
                                            if ($(this).is(':checked'))
                                            {
                                                    newVal.push( $('label[for="' + $(this).attr('id') + '"]').text());
                                            }
                                    });
                                    $chosenRecipients.val(newVal.join(', '));
                            },0);
                    });
            });
    </script>
2
  • I follow that about 60%...;) I thought User Recipients was for open-ended filling in of email addresses? These need to be a set selection associated with a checkbox field. Does it change things if I only need the Recipient Name value instead of email? – Michael Boyink Aug 28 '13 at 18:44
  • Oh, yes that does change things actually. Edited answer. – Solspace Aug 28 '13 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.