Page 1 of 1

Select E-Mail Recipents in CP Form by User

Posted: Wed 16. Apr 2008, 16:30
by marcus@localhorst
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:
Image
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.

Image

Image

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');
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

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']);
?>
if everything goes well, it will work.
try it at your own risk 8)
please send suggestions, comments, bug.
marcus

Re: Select E-Mail Recipents in CP Form by User

Posted: Thu 17. Apr 2008, 09:43
by rushclub
nice. thanks for sharing ;)

rush

Re: Select E-Mail Recipents in CP Form by User

Posted: Sat 31. May 2008, 10:52
by marcus@localhorst
I've downloaded the last phpwcms version and I think it's now possible to select from email list, without this hack.
this is just a notice, I didn't try it. :mrgreen:

Re: Select E-Mail Recipents in CP Form by User

Posted: Thu 17. Jul 2008, 10:44
by update
I have downloaded the newest too (r232), but this email selection is scrambling my input and the output is kind of unusable...
Can anybody confirm this or give some hint how to use it? Thank you!

PS: or isn't it working with the make_email_spamsafe perhaps? Didn't test it yet, but... could be... making the mail addresses of the pulldown spamsafe.... :?:

Re: Select E-Mail Recipents in CP Form by User

Posted: Thu 17. Jul 2008, 10:53
by marcus@localhorst
claus wrote:PS: or isn't it working with the make_email_spamsafe perhaps? Didn't test it yet, but... could be... making the mail addresses of the pulldown spamsafe.... :?:
take a look at the endprodukt (I mean the rendered HTML source, are the mailadresses converted?)
best m.

Re: Select E-Mail Recipents in CP Form by User

Posted: Thu 17. Jul 2008, 10:53
by update
Yes- this can be confirmed. If I move the spam-safe Script into the folder "disabled" again, everything is working....
So let's call it kind of a bug / inconsistency - I will open an issue at guuuckle code...

PS - I#ve been too late - thanks for stepping in, marcus

Re: Select E-Mail Recipents in CP Form by User

Posted: Thu 17. Jul 2008, 12:46
by jscholtysik
Hm,


the issue was closed because OG has no clue??? That's sad... :-(


Joachim

Re: Select E-Mail Recipents in CP Form by User

Posted: Thu 17. Jul 2008, 13:16
by update
JS within a selection box? hmmm - can this work? let's do some auntguuugleing ;)