Email form to multiple members

Discuss forms and the best CGIs for handling visitors info from your web site

Moderators: Chuck, Ilbin, Vanessa

Email form to multiple members

Postby fmwrc on Tue Oct 27, 2009 12:12 pm

Hello,
I was wondering with the form script; can I make it so that user can select multiple names and click submit; currently, it seems like they are not allowed to pick the names they want to send the form content to...? please help!

Thank you.
fmwrc
Forum User
 
Posts: 4
Joined: Tue Oct 27, 2009 12:09 pm

Re: Email form to multiple members

Postby Marco on Wed Oct 28, 2009 5:09 am

Hello!

To be honest this type of functionality isn't built into Form Mail ( I assume you are using FormMail ) but with a few modified lines of code you could make that happen. Let me know exactly what Form software you are using and I'll see if I can help.

Marco
System Administration
InMotion Hosting, Inc. 888.321.4678
Search for solutions | IMH Support Center | Knowledge Base | Open Support Request
User avatar
Marco
InMotion Staff
 
Posts: 213
Joined: Tue Aug 19, 2008 7:17 am
Location: Virgina Beach, VA

Re: Email form to multiple members

Postby fmwrc on Wed Oct 28, 2009 8:32 am

Marco,
I am using FormMail; and Dreamweaver to create my form (very basic). Anything you can suggest would be great!
fmwrc
Forum User
 
Posts: 4
Joined: Tue Oct 27, 2009 12:09 pm

Re: Email form to multiple members

Postby Marco on Fri Oct 30, 2009 10:12 am

Okay, there are a few ways to do this. You can easily make the HTML as follows:

Code: Select all
<input type="hidden" name="recipient" id="recipient" value="email1@domain.tld,email2@domain.tld">

However if I understand this correctly you are looking for the user to select which address. You can easily place this snip-it into the form:

Code: Select all
<select name="recipientList[]" multiple="multiple">
   <option value="email1@domain.tld">First Person</option>
   <option value="email2@domain.tld">Second Person</option>
   <option value="email3@domain.tld">Thrid Person</option>
   <option value="email4@domain.tld">Fourth Person</option>
</select>

This isn't quite enough though as it reports to the script in the form of an array and needs to be comma delimited. We could and modify the formmail script and that would probably be the more direct way to go - however I don't like modifying the code base of other production script (especially when I didn't make it) If you update or upgrade the script later the changes made will be lost. So - this is the solution I've come up with.

Code: Select all
<html>
<head>
<script type="text/javascript" language="Javascript">
var arSelected = new Array();
function getMultiple(ob)
{
   while (ob.selectedIndex != -1)
   {
      if (ob.selectedIndex != 0) arSelected.push(ob.options[ob.selectedIndex].value);
      ob.options[ob.selectedIndex].selected = false;
   }
   document.getElementById('recipient').innerHTML = arSelected.join();
}
</script>
... YOUR HTML ...
<i>Hold Ctrl to select multiple recipients</i><br>
<select name="recipientList" multiple="multiple" onClick='getMultiple(this);>
   <option value="email1@domain.tld">First Person</option>
   <option value="email2@domain.tld">Second Person</option>
   <option value="email3@domain.tld">Thrid Person</option>
   <option value="email4@domain.tld">Fourth Person</option>
</select>
<input type="hidden" name="recipient" id="recipient" value="">
... REST OF HTML ...
</html>

You need to insert the script portion between the <HEAD> tag ( if you don't have a head tag it would look like this:

Code: Select all
<html>
<head>
<title>Title</title>
<script>
</script>
</head>
<body>

So on and so forth.

Then insert the second portion of the code (the select block and hidden tag) in your form where you want the user to select the people. (this needs to be between the <form> and </form> tag).

Whenever someone selects a recipient it will automatically insert the email address into the hidden "recipient" html tag. If multiple are selected it will append each with a "," as required by FormMail.

This code hadn't been 100% tested - but, for the most part is sound. If you have problems let me know where your form is and I'll see if I can help you further.

Marco
System Administration
InMotion Hosting, Inc. 888.321.4678
Search for solutions | IMH Support Center | Knowledge Base | Open Support Request
User avatar
Marco
InMotion Staff
 
Posts: 213
Joined: Tue Aug 19, 2008 7:17 am
Location: Virgina Beach, VA

Re: Email form to multiple members

Postby fmwrc on Tue Nov 03, 2009 6:31 am

Hi Marco,
Thank you so much for helping me with this. Here is where my form is at: http://www.mwrbrandcentral.com/RequestForm.html

I tried to insert your code ... but I wasn't able to/wasn't sure where to insert the second part. At the top of my form... where they pick "Account Manager:", I like the submit button at the bottom to go the account managers that were chosen.

Last thing, my five File Fields; I am not getting the attachments to my email account?! what am I doing wrong?

Thank you again!
fmwrc
Forum User
 
Posts: 4
Joined: Tue Oct 27, 2009 12:09 pm

Re: Email form to multiple members

Postby Marco on Tue Nov 03, 2009 7:33 am

Hello!

Okay, I have modified your source code and implemented the changes for selecting multiple addresses. You can view the changes in your file. What you will need to change is this portion:

Code: Select all
          <select name="Account Manager" size="7" multiple="multiple" class="AccountManagerNames" id="AccountManager" onClick="getMultiple(this);">
            <option value="Adam.Roy@emailaddress.com">Adam Roy</option>
            <option value="Amy.Leon@emailaddress.com">Amy Leon</option>
            <option value="Beth.Horner@emailaddress.com">Beth Horner</option>
            <option value="Carrie Pollard">Carrie Pollard</option>
            <option value="Jennifer Morris">Jennifer Morris</option>
            <option value="Joanie Duncan">Joanie Duncan</option>
            <option value="Joseph Rayzor">Joseph Rayzor</option>
            <option value="Kristen Kea">Kristen Kea</option>
            <option value="Kristen McManus">Kristen McManus</option>
            <option value="Robin Hovey">Robin Hovey</option>
          </select>


I started at the top showing you what the "value" portion should be. That should be the equivalent of their Email address. Otherwise that will work. As for the file uploading I'm not entirely sure. I'll see if I can look further into that.

Marco
System Administration
InMotion Hosting, Inc. 888.321.4678
Search for solutions | IMH Support Center | Knowledge Base | Open Support Request
User avatar
Marco
InMotion Staff
 
Posts: 213
Joined: Tue Aug 19, 2008 7:17 am
Location: Virgina Beach, VA

Re: Email form to multiple members

Postby fmwrc on Wed Nov 04, 2009 5:39 am

Marco,
Thank you!!! you are awesome :]
fmwrc
Forum User
 
Posts: 4
Joined: Tue Oct 27, 2009 12:09 pm


Return to Creating and Using Forms

Who is online

Users browsing this forum: No registered users and 1 guest