Select E-Mail Recipents in CP Form by User
Posted: Wed 16. Apr 2008, 16:30
This is a workaround if you want to send a form to different e-mail addresses, selected by a user in frontend.
CASE: You build a form with the Form Contentpart, and you want the user select to which recipient he send his request.
maybe 2 hospitals:
In PHPwcms ContentPart Form, there are some little limitations for formfieldoptions and mailroutine so I find a simple way to make this work.
Maybe there is still a solution or there might be a better way, this works for me:
Setup a SELECT field in PHPWCMS CP Form and a EMAIL field which will be hidden in frontend. This is just to have the $_POST variable present and we can choose this Field as Global recipent in CP Form
The Value field of the Select should hold your options.
The Selectfield holds your options - that could be different Locations or categories.
Please hold in mind, these should be contains unique phrases.
Now we setup the unique recipents, mapped to the different options on select.
open the file /config/phpwcms/config.inc.php and add the following value somewhere before define('PHPWCMS_INCLUDE_CHECK', true);
Please keep in mind, to set the array keys just as a single string, without space or special chars, because we use these strings to identify the $_POST value choosen from the selectfield, via regular expressions!
(if someone has a better idea, please tell me. Maybe it is possible in future to set different values in selectfields in phpwcms backend)
then go to template/inc_script/frontend_init and create a new file called formmail_recipents.php with the following content
if everything goes well, it will work.
try it at your own risk
please send suggestions, comments, bug.
marcus
CASE: You build a form with the Form Contentpart, and you want the user select to which recipient he send his request.
maybe 2 hospitals:
In PHPwcms ContentPart Form, there are some little limitations for formfieldoptions and mailroutine so I find a simple way to make this work.
Maybe there is still a solution or there might be a better way, this works for me:
Setup a SELECT field in PHPWCMS CP Form and a EMAIL field which will be hidden in frontend. This is just to have the $_POST variable present and we can choose this Field as Global recipent in CP Form
The Value field of the Select should hold your options.
The Selectfield holds your options - that could be different Locations or categories.
Please hold in mind, these should be contains unique phrases.
Now we setup the unique recipents, mapped to the different options on select.
open the file /config/phpwcms/config.inc.php and add the following value somewhere before define('PHPWCMS_INCLUDE_CHECK', true);
Code: Select all
$phpwcms['formmailer_recipents'] = array('EKA'=>'email@eka.de','DRK'=>'email@drk.de');
//this would be possible too:
//$phpwcms['formmailer_recipents'] = array('Berlin'=>'berlin@your-email.de','Hamburg'=>'hamburg@your-email.de','dresden'=>'dresden@your-email.de');
(if someone has a better idea, please tell me. Maybe it is possible in future to set different values in selectfields in phpwcms backend)
then go to template/inc_script/frontend_init and create a new file called formmail_recipents.php with the following content
Code: Select all
<?php
// selectable formmailer_recipents in frontend by marcus@localhorst
if($GLOBALS['phpwcms']['formmailer_recipents'])
{
$search = implode("|",array_keys($GLOBALS['phpwcms']['formmailer_recipents']));
if (preg_match("/".$search."/",$_POST['select_email'],$f))
{
if(array_key_exists($f[0],$GLOBALS['phpwcms']['formmailer_recipents']))
{
$_POST['target_email'] = $GLOBALS['phpwcms']['formmailer_recipents'][$f[0]];
}
}
}
else
{
// in case the value doesn't exist in conf.inc.php, we send the mail to the admin email
// so he know - something went wrong
$_POST['target_email'] = $GLOBALS['phpwcms']['admin_email'];
}
// -- undcomment print_r() to debug
// the mapped recipents
#print_r($GLOBALS['phpwcms']['formmailer_recipents']);
// the found unique string
#print_r($f);
// the right email
#print_r($_POST['target_email']);
?>
try it at your own risk
please send suggestions, comments, bug.
marcus