ericlbarnes / Statamic-email-form

Email form plugin for Statamic
http://ericlbarnes.com/blog/statamic-email-form-plugin
Other
36 stars 6 forks source link

Multiple recipients #27

Closed shoostar closed 9 years ago

shoostar commented 9 years ago

I apologize for posting this here, as I do realize that Github is for posting issues, and not necessarily questions about how to do something, but I'm not sure where else to post.

Anyways, so I'm building a contact form for my Statamic-powered website using this plugin, and I can get it to work just fine locally using hMailserver. My question is this:

Let's say I want to give the person that's filling out this form the option to send it to one of multiple recipients. Now, I'm no expert in how to accomplish this, but I think I've got a bit of a start, and just don't know how to finish it up. What I've done is created a new select field, with the name of "email-address" (to keep things simple for now), and each option has a different person specified as a recipient, with their email address populating the "value" area. How would I go about plugging in this address into the "to" variable? I've tried doing something like this:

{{ email_form subject="Contact Form" to="email-address" required="first-name" }}

but I get a Slim error that looks like this:

Type: ErrorException
Code: 8
Message: Undefined index: email-address
File: D:\wamp\www\snowstorm-nopp\_add-ons\email_form\pi.email_form.php
Line: 163

Although I'm no expert on how to fix this, I know I'm (obviously) missing something here, but the problem is, what exactly would that be? What other changes do I need to make to the contact form itself, as well as the actual plugin file (pi.email_form.php) to get this to work correctly? The form itself isn't complicated at all (name, phone number, email, recipient, and message), but having the ability to choose the recipient of this email is quite vital for what I'm trying to achieve. Any chance someone could give me a little help on this?

ericlbarnes commented 9 years ago

I believe you would want to do something like this. I'm just doing this off the top of my head and you probably should add some validation and maybe not include the emails in the form like I am.

<select name="to">
   <option value="john@doe.com">John</option>
   <option value="steve@doe.com">Steve</option>
</select>

Then in the pi.email_form.php change:

$options['to'] = $this->fetchParam('to');

to:

$options['to'] = $_POST['to'];

Just reply if you have any questions.

shoostar commented 9 years ago

Thanks, I'll take a look at this tomorrow when I get back to the office. I do have some JS validation running on the side for this form right now, so that's one thing ticked off the list :)

shoostar commented 9 years ago

That doesn't quite seem to fix the problem, as I'm now getting this error message:

Type: ErrorException
Code: 8
Message: Undefined index: to
File: D:\wamp\www\snowstorm-nopp\_add-ons\email_form\pi.email_form.php
Line: 21