Select E-Mail Recipents in CP Form by User

If you have created additional (non official) documentation or tutorials or something like that please post this here
Post Reply
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Select E-Mail Recipents in CP Form by User

Post 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
rushclub
Posts: 915
Joined: Tue 17. Feb 2004, 18:52

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

Post by rushclub »

nice. thanks for sharing ;)

rush
3 (!) Jahre warten reichen mir. Ich bin erst mal weg.
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

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

Post 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:
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

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

Post 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.... :?:
It's mostly all about maintaining two or three customer's sites Still supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.
Now building a venue for young artists to get wet on stage, rehearsal rooms, a studio, a guitar shop - yes I'm going to build some guitars.
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

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

Post 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.
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

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

Post 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
It's mostly all about maintaining two or three customer's sites Still supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.
Now building a venue for young artists to get wet on stage, rehearsal rooms, a studio, a guitar shop - yes I'm going to build some guitars.
jscholtysik

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

Post by jscholtysik »

Hm,


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


Joachim
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

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

Post by update »

JS within a selection box? hmmm - can this work? let's do some auntguuugleing ;)
It's mostly all about maintaining two or three customer's sites Still supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.
Now building a venue for young artists to get wet on stage, rehearsal rooms, a studio, a guitar shop - yes I'm going to build some guitars.
Post Reply