Field transfer V2

Based on a local selection a certain email address is selected and passed over. Version 02.

Advantages over V1:

  • The complete case of an error in the select menu “Ortsauswahl” will be covered. Even if a second incorrect input is following a first one, the focus will remain in the drop down box previously selected.
  • The e-mail addresses are included in encoded form to give SPAM robots no selection possibility.

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.




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

  • $phpwcms['allow_ext_init'] = 1;



Example:


There are several regions, each is assigned an email address to contact the right person for this region.

  • The region is one of many and can be selected in a pull-down menu. The email address of the contact person is assigned.
  • It often happens that several regions will be managed by one person, thus stored identical email addresses.
  • In the text of the initial email the selected region is shown.

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:

FIXME translate

  • To catch all errors and enable us to make use of the selection we'll set up a simple pulldown menu.
    Our selection can then be determined via $postvar['ortsauswahl'].
  • The relation between place and E-mail address will be stored in the hidden field “ort_email” (Variable $_POST['ort_email']).
  • For the output of the place we have to created a hidden field “ort” (Variable $_POST['ort']).
  • To enable the output of the eMail address we'll need to create an E-Mail field “email” (Variable $_POST['email']) to be able to fill in “email” as the sender address.

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).


Script:

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.


Backend:

[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:

recipient - template

Hallo {anrede} {name},

E-Mail: {email}

Ort:    {ort}

Kommentar:
------------------------------
{kommentar}
------------------------------

Das war alles - Danke.

Template:

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>
english/phpwcms-system/article/contentparts/form/special-applications/php-script-and-function/field-transfer-v2.txt · Last modified: 2012/02/02 09:03 by Knut Heermann (flip-flop)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0