This is an old revision of the document!


PHP-Script- and function

FIXME better 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

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

A simple script in “template/inc_script/frontend_init/” -folder is processed before the PHP function call of 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

<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. </note>



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;



Example:


(In the graph: replace the texte-mail by location).

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 are shown.

The last requirement excludes the use of the form from PHP function because we can not relate in a typical building a response 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 selects 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 selects. (Obelix is responsible for both places).

Extended Version:

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

The form PHP function would provide in “$postvar['email'] ⇒ obelix@lokal.arpa”, thus also here no localisation would be possible. (<Laudanum> is filtered by the form Script).

The variable “$_POST['email']” in an frontend_init-Script supplies against it e.g. ” obelix@lokal.arpa”. We can determine the place.

To fix the location in the output text, we place a hidden field “location” with the word “nix” (nothing) into the form. This field can also be used to identify the form, the frontend_init script is executed on every page request!

Script:

E.g.

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

Thus, the form will be identified at least rudimentary. This is important when multiple forms are used on the site..

The last step is to restrict the location and assignment to the variable “$_POST['ort']”.
This is possible with a simple preg_replace.

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']
 
 
?>

The right location is passed to the form.

For testing have a look in the forms PHP function into the variable “$postvar['ort']. The text “Laudanum” will be entered there. Thus, this text is taken over in the text of the outbound email for the placeholder ”{ort}”.


Backend:

[select email menu] 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


recipient - template:

Empfängervorlage

Hallo {anrede} {name},

E-Mail: {email}

Ort:    {ort}

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

Das war alles - Danke.

template:

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