Differences

This shows you the differences between two versions of the page.

english:phpwcms-system:article:contentparts:form:special-applications:php-script-and-function [2010/07/14 07:51]
Knut Heermann (flip-flop) created
english:phpwcms-system:article:contentparts:form:special-applications:php-script-and-function [2018/06/03 18:09] (current)
Line 3: Line 3:
====== PHP-Script- and function ====== ====== PHP-Script- and function ======
-FIXME translate+FIXME better translate
-Seit der Release r282 ist es möglich eine eigene PHP-Funktion zwischen der Aktion "submit" und "dem Versenden der eMail" abzuarbeiten . Diese Funktion kann alle Formulareingaben lesen, viele verändern und zurückgeben. Siehe: [[english/phpwcms-system/article/contentparts/form/special-aplications/php-function-include]]+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: [[english/phpwcms-system/article/contentparts/form/special-applications/php-function-include]]
-In dieser Funktion kann die eMailadresse nicht manipuliert werden. Brauchen wir jedoch diese Möglichkeit, muss auf ein anderes Verfahren zurückgegriffen werden. +However, the changed data is not recorded in the database, since these data have been written into it before. If we need this possibility, we have to switch over to another method.
-Ein einfaches Script im "template/inc_script/frontend_init/" -Ordner wird vor dem PHP Funktionsaufruf aus dem Formular heraus abgearbeitet.  +A simple script in template/inc_script/frontend_init/ -folder is processed before the PHP function call of the form.
- +
-**Reihenfolge:** +
-  - Ausliefern des Formulars an den Browser +
-  - Submit: Empfangen des Formulars mit den Usereingaben +
-  - Abarbeiten der /frontend_init/ -Scripte +
-  - Abarbeiten der PHP-Funktion aus dem Formular+
\\ \\
----- 
----- 
-Docu: -- \\ +The fundamental differences between a normal %%/frontend_init/..%% -Script and the special script //(PHP function :)// which can be triggered from the form:
-Forum: --+
-**Autor:** [[http://planmatrix.de|K.Heermann]] //(flip-flop) (13.07.2010)// \\ +  * **Normal %%/frontend_init/..%% -Script**: All entries will be displayed in the variable **$_POST**. The values ​​are in %%$_POST['EingabefeldName']%% and may be changed.. //(The changes are written to the DB.)//
-**CMS-Version:** >= V1.4.1 r282 \\ +
-**Version:** V1.0 //13.07.2010// \\+
 +  * **Form %%/frontend_init/..%% -Script** //(PHP function:)//: The input variables **$mail** and **$postvar** are shown, but can not be changed. Die The templates "Send To" and "send copy to" in the variable **$form** are shown and can be changed. //(The changes are not written to the DB.)//
-**Bedingung:**  -> [[http://www.phpwcms-docu.de/confincphp_de.phtml|/config/phpwcms/conf.inc.php]] \\ 
-  * $phpwcms['allow_ext_init'] = 1; 
- 
----- 
----- 
\\ \\
-===== Beispiel: =====+**Processing order:** 
 +  - Deliver the form to the browser. 
 +  - User input. 
 +  - Submit: receiving the form with the user input. 
 +  - Processing the %%/frontend_init/..%% -Scripts, e.g. to manipulate the contents of the variable %%$_POST['FieldName']%%. At this point, an deliberately error can be produced. The contents of a "required" field in %%$_POST['FieldName']%% will be deleted. 
 +  - Caching of form data to the database. 
 +  - Processing PHP function call from the form. The contents of the variable %%$email%% and %%$postvar%% can be read, the contents of %%$form%% can be read and write. //(These changes are not recorded in the DB.)// 
 +  - Check the fields that must be filled out ("required"). 
 +    * On error, continue at point **1.**  with error code. 
 +  - Export the cached form data into the DB. 
 +  - Sending e-mails.
-{{:deutsch:phpwcms-system:artikel:contentparts:formular:spezielle-anwendungen:php_script_und_funktion_fe01_de_1.gif|}} +<note important
-  +Scripts in the /frontend_init/ -folder should be used with consideration, as this is an early intervention in the system process. \\  
-\\ +These scripts should differentiate the site compared to the edited excerpt in order to avoid side effects. E.g. at least query the category.  
-//(In der Grafik: Den Text E-Mail durch Ort ersetzen)//.  +</note>
- +
-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** +
-<file+
-Bitte wählen -|- +
-Babaorum -|- obelix@lokal.arpa +
-Laudanum -|- obelix@lokal.arpa  +
-Kleinbonum -|- asterix@lokal.arpa +
-Aquarium -|- idefix@lokal.arpa +
-</file> +
- +
-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:** +
-<file> +
-Bitte wählen -|- +
-Babaorum -|- <Babaorum>obelix@lokal.arpa +
-Laudanum -|- <Laudanum>obelix@lokal.arpa  +
-Kleinbonum -|- <Kleinbonum>asterix@lokal.arpa +
-Aquarium -|- <Aquarium>idefix@lokal.arpa +
-</file>  +
- +
-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. +
-<code php> +
- if(isset($_POST['email']) AND $_POST['email'] == 'nix') { ... +
-</code> +
-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.  +
- +
-<code php |h form_script_email_to_location.php |h> +
-<?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']  +
- +
- +
-?> +
-</code> +
- +
-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: ==== +===== Short link overview =====
- +
- +
-{{:deutsch:phpwcms-system:artikel:contentparts:formular:spezielle-anwendungen:php_script_und_funktion_be01_de_1.gif|}} +
- +
-**[E-Mail Aufklappmenü]** Name: **email** +
-<code> +
-Bitte wählen -|- +
-Babaorum -|- <Babaorum>obelix@lokal.arpa +
-Laudanum -|- <Laudanum>obelix@lokal.arpa  +
-Kleinbonum -|- <Kleinbonum>asterix@lokal.arpa +
-Aquarium -|- <Aquarium>idefix@lokal.arpa +
-</code>  +
- +
-\\ +
-{{:deutsch:phpwcms-system:artikel:contentparts:formular:spezielle-anwendungen:php_script_und_funktion_be02_de_1.gif|}} +
- +
-**Empfängervorlage:** +
-<code |h Empfängervorlage |h> +
-Hallo {anrede} {name},  +
- +
-E-Mail: {email} +
- +
-Ort:    {ort} +
- +
-Kommentar: +
------------------------------- +
-{kommentar} +
------------------------------- +
- +
-Das war alles - Danke. +
-</code> +
- +
-**Vorlage:** +
-<code |h Vorlage |h> +
-<!--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> +
-</code> +
- +
- +
- +
- +
- +
 +{{indexmenu>english:phpwcms-system:article:contentparts:form/special-applications/php-script-and-function|js#doku navbar msort nsort nocookie notoc}}
english/phpwcms-system/article/contentparts/form/special-applications/php-script-and-function.1279086679.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