Recipient Selector
Introduction
Notifications emails to custom addresses depending on a select input on your form by overriding mail_recipients
property of Magic Form component.
HTML Form
On your partial, add a select input to your form:
<select id="department" name="department">
<option value="marketing">Marketing</option>
<option value="sales">Sales</option>
<option value="support">Support</option>
</select>
Extend Plugin
Create your own plugin or use this as template: https://github.com/skydiver/october-plugin-formsextender
Replace your boot method with:
public function boot() {
\Event::listen('martin.forms.beforeSaveRecord', function (&$formdata, $component) {
// Get department input value
$department = $formdata['department'];
// Get department email address
switch ($department) {
case 'marketing':
$email = 'marketing@company.com';
break;
case 'sales':
$email = 'sales@company.com';
break;
case 'support':
$email = 'support@company.com';
break;
default:
$email = 'hello@company.com';
break;
}
// Override component mail recipients
$component->setProperty('mail_recipients', [$email]);
});
}