2sic / app-mobius-forms

Simple jQuery based 2sxc form - to use immediately or to modify as needed. Multi-language, simple, with Recaptcha

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Send e-mail CC based on form field

enfJoao opened this issue · comments

There could be a way to send CCs of the e-mail (either customer or owner) based on a form field.
There already is a field on the configuration entity that allows CCs to several emails, so it's just a small hijack.

  1. Create an entity for the e-mail data (I use entities for everything that places values in the form - easier to maintain)

Image of entity

  1. Create the form fields
<div style="text-align: center;">
    <div style="display: inline-block; text-align: left;">
        <b>Destinatários para envio</b>
        <br>
        @foreach(var q in AsDynamic(App.Data["entity"]).Where(z => z.zone == "1")){
            <input type="checkbox" name="contacts" value="@q.email">@q.auditor<br>
        }
    </div>
    <div style="display: inline-block; text-align: left;">
        @foreach(var q in AsDynamic(App.Data["entity"]).Where(z => z.zone == "2")){
            <input type="checkbox" name="contacts" value="@q.email">@q.auditor<br>
        }
    </div>
</div>

and

<div style="display: none;">
    <input type="text" id="mailcc" size="50">
</div>
  1. Create the script to joint the contacts
<script>
function displayMails() {
    var contacts = $('input[name="contacts"]:checked').map(function () {
        return this.value;
    }).get();
    $("#mailcc").val(contacts.join(","));
}

$(":checkbox").change(displayMails);
displayMails();
</script>
  1. Change the controller

Add
var newMailCC = contactFormRequest["mailcc"].ToString();

And change the
Mail.SendMail(settings.MailFrom, settings.OwnerMail, newMailCC, "", custMail, MailPriority.Normal,ownerSubj, MailFormat.Html, System.Text.Encoding.UTF8, ownerBody, new string[0], "", "", "", "", false);
Remove the Key mailcc and/or lsauditores if unwanted in the e-mail template

This is a very cheesy way to do this.
If needed, a proper check between the form field and the entity configuration could be implemented based on priority (if one is empty, use the other, if both are filled, use the priority one).

I believe this is so old it's not relevant any more.