Based on a local selection a certain email address is selected and passed over. Version 02.
Advantages over V1:
<note> Since version V1.4.7 R414 it is no longer necessary to apply in relation to “non-encrypted e-mail addresses” the method shown here. The e-mail addresses are encrypted from this version in the value field in FE. </note>
Docu: –
Forum: –
Author: K.Heermann (flip-flop) (16.07.2010)
CMS-Version: >= V1.4.1 r282
Version: V2.0 16.07.2010
Condition: → /config/phpwcms/conf.inc.php
There are several regions, each is assigned an email address to contact the right person for this region.
The last requirement will exclude the use of PHP function within the form because with a standard form setup we cannot build a feedback relation to the selected region. ($postvar['email'] ⇒ test@example.com) if e.g.
[select email menu] Name: email
Bitte wählen -|- Babaorum -|- obelix@lokal.arpa Laudanum -|- obelix@lokal.arpa Kleinbonum -|- asterix@lokal.arpa Aquarium -|- idefix@lokal.arpa
If the user is selecting one of the first two places e.g. “Laudanum”, an identical e-mail address is returned to us, we do not know which location the user has been selecting. (Obelix is responsible for both places).
Extended Version 2:
translate
To my opinion we have to create 4 fields to get the desired results (see below, 1-4) because we must not manipulate an input field (in this case “ortsauswahl”) any further (accidentally) in case of repeated input (case of error/reload), otherwise the session will reset an input made previously.
Therfore we'll make use of a simple input field (Articlemenu) which will not be changed through the script. The script will assign the eMail address to the chosen place with the help of s second hidden field where this relation is defined.
This eMail address is stored fairly unreadable to prevent SPAM-bots from reading them. (Ort|Name*domain:tld# —> Kleinbonum|obelix*lokal:arpa#). The #- sign is used as a between the different data and has to be set.
To incorporate the “place” in an output text we are defining a new hidden field “ort” with “nix” as the content. This field can be used to identify the form, because the frontend_init-script will be run with every page call!
The eMail address will be passed over to the field “email” and therefor can be used as the senders address also (you vannot do that with hidden fields).
E.g.
if( isset($_POST['ort']) AND isset($_POST['ort_email']) ) { ...
This way you can identify the form basically. It will be possibly helpful when more than one form has to be used.
The only step missing is filtering the “place” and assigning it to the variable “$_POST['ort']” und “$_POST['email']”.
form_script_email_to_location_v2.php
<?php /** ********************************************************************************************* * 16.07.2010 KH: http://planmatrix.de V2 * frontend_init-Script: Manipulating the e-mail address * - Determining the location and email address in form ********************************************************************************************* */ // ------------------------------------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ------------------------------------------------------------------------------------------- if( isset($_POST['ort']) AND isset($_POST['ort_email']) ) // The right form? { $ort_email = array(); $ort = trim($_POST['ortsauswahl']); // Nur ort enthalten $ort_email = explode('#', $_POST['ort_email']); // // location|text*domain:tld if (!empty ($ort_email)) foreach ($ort_email as $key=>$value) { // --- location|text*domain:tld $split =preg_split('/\|/', $value, 2); // Cutting out the location if (trim($split[0]) == $ort) { $_POST['ort'] = $ort; // assign the location // Cutting out and assign the eMail $_POST['email'] = trim(preg_replace('/(.*)\|(.*)\*(.*):(.*)/is','$2@$3.$4', $value)); break; }; } } // ---- END if( $_POST['ort'] ?>
The right location is passed to the form.
[select menu] Name: ortsauswahl
Bitte wählen-|- Babaorum Laudanum Kleinbonum Aquarium
[hidden] Name: ort_email
Babaorum|obelix*lokal:arpa# Laudanum|obelix*lokal:arpa# Kleinbonum|asterix*lokal:arpa# Aquarium|idefix*lokal:arpa#
[hidden] Name: ort
nix
[e-mail] Name: email
nix
recipient - template:
Hallo {anrede} {name}, E-Mail: {email} Ort: {ort} Kommentar: ------------------------------ {kommentar} ------------------------------ Das war alles - Danke.
Template:
<!--form-spezial//--> <div style="width:500px; margin: 0; padding:10px; border:1px solid #bbb; background: #C2E7EF;"> {ERROR:anrede}[B]{LABEL:anrede}[/B] *[BR]{anrede}[BR][BR] {ERROR:name}[B]{LABEL:name}[/B] *[BR]{name}[BR][BR] {ERROR:ortsauswahl}[B]{LABEL:ortsauswahl}[/B] *[BR]{ortsauswahl}[BR][BR] {ERROR:kommentar}[B]{LABEL:kommentar}[/B][BR]{kommentar}[BR][BR] {ERROR:nospam}[B]{LABEL:nospam}[/B] *[BR]{nospam}[BR][BR] {submitIt} </div>