0

There is a guide on GitHub page how to add additional fields, but how to add recipient selection?

1

There's no way to do this by default as far as I know so you'd need to create a small plugin to dynamically add the recipient email to the form.

You might be able to shortcut that a little by changing that hidden input value using JavaScript alone depending on what was selected in the dropdown but the toEmail param is meant to be hashed.

1

First create a new config file in your craft > config folder and name it contactform.php. This is a config for the Contact Form plugin. Next add this bit of code to it.

<?php
namespace Craft;

$toEmail = craft()->request->getPost('toEmail');
$toEmail = craft()->security->validateData($toEmail);

return array(
    'toEmail' => ($toEmail ?: null),
);

In your html create a SELECT input and give it the name name=toEmail. You could create a dynamic list with a table input. Make sure to use the hash filter when outputting your email address into value.

<select name="toEmail">
    {# emailList is handle of custom table input. #}
   {% for item in entry.emailList %}
        {# email & subject are custom table input column handles #}
       <option value="{{ item.email|hash }}">{{ item.subject }}</option>
   {% endfor %}
</select>
2
  • Thank you. Do I miss something obvious? As I'm getting Getting Variable "entry" does not exist for {% for item in entry.emailList %}. Sorry for noob question. I tried to set by {% set entry = craft.entries.id(5) %} but doesn't seem to work, getting in result a plain drop-down.
    – curious
    Feb 20 '17 at 21:02
  • No problem entry is the default variable provided by Craft when you are visiting an entries url. Use whatever variable to access the custom table you created. Change your set entry to something else. {% set pageVar = craft.entries.id(5) %} then ``` {% for item in pageVar.emailList %}``` assuming emailList is the handle you set for your custom table input.
    – aran
    Feb 20 '17 at 21:05

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.