Skip to content

Instantly share code, notes, and snippets.

@Jako
Created October 18, 2019 17:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jako/0679e1b23cb8f5c5494c6826eba0f6a9 to your computer and use it in GitHub Desktop.
Save Jako/0679e1b23cb8f5c5494c6826eba0f6a9 to your computer and use it in GitHub Desktop.
MODX FormIt Email Selector
<?php
$selectField = $modx->getOption('emailSelectField', $scriptProperties, 'department');
$selectTo = $modx->getOption('emailSelectTo', $scriptProperties, '');
$selectTo = ($selectTo) ? explode(',', $selectTo) : array();
if ($selectField && $selectTo) {
$selected = intval($hook->getValue($selectField)) - 1;
if ($selected && isset($selectTo[$selected])) {
$hook->formit->config['emailTo'] = $selectTo[$selected];
}
}
return true;
@Jako
Copy link
Author

Jako commented Oct 18, 2019

Switch the emailTo address on base of a select dropdown.

Snippet Properties:

&hooks=`emailselect,...`
&emailSelectTo=`mail@my.domain,different@my.domain`
&emailSelectField=`emailselect`

Form Field:

        <select name="emailselect">
            <option value="1" [[!+fi.emailselect:FormItIsSelected=`1`]]>Address 1</option>
            <option value="2" [[!+fi.emailselect:FormItIsSelected=`2`]]>Address 2</option>
        </select>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment