As I was desperately searching how to use TV to build dynamically my mailinglist (see
http://modxcms.com/forums/index.php/topic,33511.0.html), I’ve given up using a TV for this and reached my goal through a snippet.
I manage my mailinglist through webgroups in Modx. So I need the
&to parameter in
eForm to be build dynamically with email addresses from a webgroup.
I use an easy eForm call that contains a snippet call in the &to parameter:
[!eForm? &formid=`feedbackForm` &to=`[[WebGroupMail? &webgroup=`Bureau`]]` &from=`[+email+]` &fromname=`[+name+]` &tpl=`eFormContact` &report=`eFormEmail` &thankyou=`eFormOKMerci` &vericode=`1` &subject=`Message de [+name+] ([+department+])` &language=`en`!]
The snippet
WebGroupMail looks like that :
<?php
/**
* WebGroupMail Snippet 1.0
* @author Hamster Jovial
* @version 1.0
*
*
*/
// Variable verification
// we need the webgroup name
if (!isset($webgroup)) {return "nobody@nodomain"; }
// Get the webgroup id
$tblWebGroupNames = $modx->getFullTableName("webgroup_names");
$requete1 = "SELECT `id`"
." FROM {$tblWebGroupNames}"
." WHERE `name` = \"$webgroup\"";
$webgroupID = $modx->db->getValue( $modx->db->query( $requete1 ) );
// the webgroupID will be used to query the members and their email addresses
// First of all : define variables for both web_groups table and web_user_attributes
$tblWebGroups = $modx->getFullTableName("web_groups");
$tblWebUserAtt= $modx->getFullTableName("web_user_attributes");
// Query
$requete2 = "SELECT email"
." FROM {$tblWebUserAtt}"
." WHERE internalkey in (select webuser from {$tblWebGroups} WHERE webgroup = {$webgroupID})";
$sql = $modx->db->query( $requete2 );
// Array resulting
$col = $modx->db->getColumn( 'email', $sql );
for( $i = 0; $i < count( $col ); $i++ )
{
if (isset($listadress))
{ $listadress.= ",".$col[$i]; }
else
{ $listadress = $col[$i]; }
}
return $listadress;
?>
the return of the snippet looks like
[email protected],
[email protected],
[email protected] etc...
So adding/removing an email address only goes through webgroup management

I hope it can be usefull for some of you
Olivier