This is an old revision of the document!


PHP-Script- and function

FIXME translate

Since the release of r282 it is possible to process an own PHP function between the action “submit” and “sending the E-Mail”. This function can read all the form input, modify, and return it. See: PHP function include

In this function, the e-mail address can not be manipulated. If we need this possibility, we have to resort to another method.

A simple script in “template/inc_script/frontend_init/” -folder is processed before the PHP function call from the form.

Processing order:

  1. Deliver the form to the browser
  2. Submit: receiving the form with the user input
  3. Processing the /frontend_init/ -Scripts
  4. Processing PHP function call from the form




Docu: –
Forum: –

Author: K.Heermann (flip-flop) (13.07.2010)
CMS-Version: >= V1.4.1 r282
Version: V1.0 13.07.2010

Condition:/config/phpwcms/conf.inc.php

  • $phpwcms['allow_ext_init'] = 1;



Beispiel:


(In der Grafik: Den Text E-Mail durch Ort ersetzen).

Es gibt verschiedene Regionen, denen jeweils eine eMailadresse zugeordnet wird um den richtigen Ansprechpartner für diese Region zu kontaktieren.

  • Die Region ist eine von vielen und kann in einem Pulldown-Menü ausgewählt werden. Die eMailadresse des Ansprechpartners wird zugeordnet.
  • Es kommt häufig vor, dass mehrere Regionen von einer Person betreut werden, also identische eMailadressen hinterlegt werden müssen.
  • Im Text der Ausgangs-eMail soll auch die gewählte Region ausgewiesen werden.

Die letzte Forderung schließt die Verwendung der Formular PHP-Funktion aus, da wir bei einem typischen Aufbau keine Rückmeldung zur ausgewählten Region beziehen können. ($postvar['email'] ⇒ test@example.com) wenn z.B.

[E-Mail Aufklappmenü] Name: email

Bitte wählen -|-
Babaorum -|- obelix@lokal.arpa
Laudanum -|- obelix@lokal.arpa 
Kleinbonum -|- asterix@lokal.arpa
Aquarium -|- idefix@lokal.arpa

Wählt der Benutzer einen der beiden ersten Orte z.B. “Laudanum”, wird uns eine identische eMailadresse zurückgeliefert, wir wissen nicht welchen Ort der Benutzer selektiert hat. (Obelix ist für beide Orte zuständig).

Erweiterte Variante:

Bitte wählen -|-
Babaorum -|- <Babaorum>obelix@lokal.arpa
Laudanum -|- <Laudanum>obelix@lokal.arpa 
Kleinbonum -|- <Kleinbonum>asterix@lokal.arpa
Aquarium -|- <Aquarium>idefix@lokal.arpa

Die Formular PHP-Funktion würde in der Variablen “$postvar['email'] ⇒ obelix@lokal.arpa” liefern, also wäre auch hier keine Ortsbestimmung möglich. (<Laudanum> wird vom Formularscript gefiltert).

Die Variable “$_POST['email']” in einem frontend_init-Script liefert dagegen z.B. ”<Laudanum>obelix@lokal.arpa”. Wir können den Ort bestimmen.

Um den Ort im Ausgabetext zu verankern legen wir ein verstecktes Feld “ort” mit dem Inhalt “nix” an. Dieses Feld kann auch zur Identifikation des Formulars dienen, denn das frontend_init-Script wird bei jedem Seitenaufruf abgearbeitet!

Script:

Z.B.

 if(isset($_POST['email']) AND $_POST['email'] == 'nix') { ...

So kann das Formular zumindest rudimentär identifiziert werden. Dies kann bei mehreren Formularen in der Site wichtig sein.

Der letzte Schritt ist die Filterung des Ortes und Zuweisung zur Variablen “$_POST['ort']”.
Das ist mit einem einfachen preg_replace möglich, je nach Gusto.

form_script_email_to_location.php

<?php
/**
 *********************************************************************************************
 * 13.07.2010 KH: http://planmatrix.de
 * 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 $_POST['ort'] == 'nix' )  // The right form?
{
    $email = trim($_POST['email']);
 
    $_POST['ort']   = preg_replace('/\<(.*)\>(.*)/is','$1', $email); // Cutting out the location
    $_POST['email'] = preg_replace('/\<(.*)\>(.*)/is','$2', $email); //Only for completeness. Is not necessarily needed
 
} // ---- END if( $_POST['ort']
 
 
?>

In der Formular PHP-Funktion wird in der Variablen “$postvar['ort'] der Text “Laudanum” stehen und somit auch in den Text der Ausgangs-eMail im Platzhalter ”{ort}” übernommen.


Backend:

[E-Mail Aufklappmenü] Name: email

Bitte wählen -|-
Babaorum -|- <Babaorum>obelix@lokal.arpa
Laudanum -|- <Laudanum>obelix@lokal.arpa
Kleinbonum -|- <Kleinbonum>asterix@lokal.arpa
Aquarium -|- <Aquarium>idefix@lokal.arpa


Empfängervorlage:

Empfängervorlage

Hallo {anrede} {name},

E-Mail: {email}

Ort:    {ort}

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

Das war alles - Danke.

Vorlage:

Vorlage

<!--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:email}[B]{LABEL:email}[/B] *[BR]{email}[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.1279087135.txt.gz · Last modified: 2018/06/03 18:07 (external edit)
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