NAVIGATION
This is an old revision of the document!
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.
The function call must be registered in the form in the fields “php function:” below “recipient template:“ or “copy to - template:“. (See picture below).
The function itself is stored in a file in folder “template/inc_script/frontend_init/” .
function my_form_title_recipient_de( &$postvar, &$form, &$mail ) { .... } function my_form_title_copy_to_de( &$postvar, &$form, &$mail ) { .... }
Docu: –
Forum: –
Author: K.Heermann (flip-flop) (22.01.10)
CMS-Version: >= V1.4.1 r282
Version: V1.0 22.01.10
Condition: → /config/phpwcms/conf.inc.php
The e-mails to the user (To) and the site operators (CC) is to be given a correct address, which is controlled by the address selection
[Frau] - [Herr] - [Firma] ([Mrs] - [Mr] - [company])
In german language we have difficult titles like “Sehr geehrte Frau” - “Sehr geehrter Herr” instead of your Dear Ms / Miss / Mrs / Mr:
[Frau] "Sehr geehrte Frau ...." [Herr] "Sehr geehrter Herr ...." [Firma] "Sehr geehrte Damen und Herren"
In addition, the dispatches e-mail will be displays again after the “send” (submit).
The simple form in backend.
Specificities:
The field “on success:“ must be labeled as HTML, because this field will be used for the display of the sent e-mail. (Is filled by the script).
Please pay attention to the placeholder [%TITLE%] in the templates and the entries
- my_form_title_recipient_de below “recipient template” and
- my_form_title_copy_to_de below “copy to - template”
in “php function:“.
… are coincidentally identical.
Name: {title} {name} E-Mail: {email} Nachricht: ------------------------------ {notice} ------------------------------ [%TITLE%], wir bedanken uns für das Interesse und werden uns in Kürze bei Ihnen melden. Mit freundlichem Gruß Sir-Oblong-Fitz-Oblong
The templates can also be generated as HTML. The output after sending works correctly.
<div style="width:510px; padding:10px; margin:10px; border:1px dotted #666; background: #E2DFFF;"> <span style="color:red">[B]{ERROR:title}[/B]</span> [B]{LABEL:title}[/B][BR]{title}[BR][BR] <span style="color:red">[B]{ERROR:name}[/B]</span> [B]{LABEL:name}[/B][BR]{name}[BR][BR] <span style="color:red">[B]{ERROR:email}[/B]</span> [B]{LABEL:email}[/B][BR]{email}[BR][BR] <span style="color:red">[B]{ERROR:notice}[/B]</span> [B]{LABEL:notice}[/B][BR]{notice}[BR][BR] <span style="color:red">[B]{ERROR:nospam}[/B]</span> [B]{LABEL:nospam}[/B][BR]{nospam}[BR][BR] {submitIt} </div>
Contents of the array $postvar using
dumpVar($postvar);
function my_form_id( &$postvar, &$form, &$mail ) { dumpVar($postvar); }
Array ( [title] => Herr [name] => Franz Mustermann [email] => f-mustermann@example.com [notice] => Bitte geben Sie hier Ihre Nachricht ein [nospam] => 12 )
Content of the arrays $form using
dumpVar($form);
function my_form_id( &$postvar, &$form, &$mail ) { dumpVar($form); }
Array ( [subject] => Vom Kontaktformular example.com [startup] => [B]E-Mail versenden![/B][BR] [startup_html] => 0 [class] => [error_class] => error [label_wrap] => Array ( [0] => [1] => ) [cform_reqmark] => * [cc] => Array ( [0] => formular@example.com ) [targettype] => emailfield_email [target] => Array ( [0] => f-mustermann@example.com ) [subjectselect] => [sendertype] => system [sender] => kontakt@example.com [sendernametype] => custom [sendername] => [verifyemail] => [labelpos] => 2 [sendcopy] => 1 [copyto] => Franz Mustermann [formtracking_off] => 1 [checktofrom] => 0 [onsuccess_redirect] => 2 [onerror_redirect] => 2 [onsuccess] => [B]Die E-Mail wurde erfolgreich gesendet![/B][BR]<div style="width:510px; padding:10px; margin:10px; border:1px dotted #666; background:#eee;">Name: Herr Franz Mustermann <br /> <br /> E-Mail: f-mustermann@example.com <br /> <br /> Nachricht: <br /> ------------------------------ <br /> Bitte geben Sie hier Ihre Nachricht ein <br /> ------------------------------<br /> <br /> <br /> Sehr geehrter Herr Franz Mustermann, <br /> <br /> wir bedanken uns für das Interesse und werden uns in Kürze bei Ihnen melden. <br /> <br /> <br /> Mit freundlichem Gruß<br /> <br /> Sir-Oblong-Fitz-Oblong</div><div style="padding:20px 0 0 20px; font-weight:bold;"><a href="category04_01_05.phtml"> >>Weiter >></a></div> [onerror] => <span style="color:red">[B]Bitte achten Sie auf den unten angezeigten Fehler![/B]</span> [template_format] => 0 [template] => Name: Herr Franz Mustermann E-Mail: f-mustermann@example.com Nachricht: ------------------------------ Bitte geben Sie hier Ihre Nachricht ein ------------------------------ Sehr geehrter Herr Franz Mustermann, wir bedanken uns für das Interesse und werden uns in Kürze bei Ihnen melden. Mit freundlichem Gruß Sir-Oblong-Fitz-Oblong [template_format_copy] => 0 [template_copy] => Name: Herr Franz Mustermann E-Mail: f-mustermann@example.com Nachricht: ------------------------------ Bitte geben Sie hier Ihre Nachricht ein ------------------------------ Sehr geehrter Herr Franz Mustermann, wir bedanken uns für das Interesse und werden uns in Kürze bei Ihnen melden. Mit freundlichem Gruß Sir-Oblong-Fitz-Oblong [function_to] => my_form_title_recipient_de [function_cc] => my_form_title_copy_to_de [template_equal] => 0 [customform] => <div style="width:510px; padding:10px; margin:10px; border:1px dotted #666; background: #E2DFFF;"> <span style="color:red">[B]{ERROR:title}[/B]</span> [B]{LABEL:title}[/B][BR]{title}[BR][BR] <span style="color:red">[B]{ERROR:name}[/B]</span> [B]{LABEL:name}[/B][BR]{name}[BR][BR] <span style="color:red">[B]{ERROR:email}[/B]</span> [B]{LABEL:email}[/B][BR]{email}[BR][BR] <span style="color:red">[B]{ERROR:notice}[/B]</span> [B]{LABEL:notice}[/B][BR]{notice}[BR][BR] <span style="color:red">[B]{ERROR:nospam}[/B]</span> [B]{LABEL:nospam}[/B][BR]{nospam}[BR][BR] {submitIt} </div> [savedb] => 1 [saveprofile] => 0 [fields] => Array ( [1] => Array ( [type] => select [name] => title [label] => Anrede [required] => 0 [value] => Frau Herr Firma [error] => Fehler:- [style] => [class] => [profile] => [size] => [max] => ) [2] => Array ( [type] => text [name] => name [label] => Name [required] => 1 [value] => Franz Mustermann [error] => Fehler:- [style] => [class] => [profile] => [size] => 48 [max] => ) [3] => Array ( [type] => email [name] => email [label] => eMail [required] => 1 [value] => f-mustermann@example.com [error] => Fehler:- [style] => [class] => [profile] => [size] => 48 [max] => ) [4] => Array ( [type] => textarea [name] => notice [label] => Nachricht [required] => 0 [value] => Bitte geben Sie hier Ihre Nachricht ein [error] => Fehler:- [style] => [class] => [profile] => [size] => 37 [max] => 3 ) [5] => Array ( [type] => mathspam [name] => nospam [label] => Spamschutz [required] => 1 [value] => Array ( [+] => Summieren [-] => Subtrahieren [*] => Multiplizieren [:] => Dividieren [calc] => Berechnung: ) [error] => Fehler:- [style] => [class] => [profile] => [size] => 10 [max] => ) [6] => Array ( [type] => submit [name] => submitIt [label] => Senden [required] => 0 [value] => Senden [error] => Fehler:- [style] => [class] => [profile] => [size] => [max] => ) ) [is_enctype] => [regx_pattern] => Array ( [A-Z] => /^[A-Z]+$/ [a-Z] => /^[a-zA-Z]+$/ [a-z] => /^[a-z]+$/ [0-9] => /^[0-9]+$/ [PHONE] => /^[+]?([0-9]*[\.\s\-\(\)\/]|[0-9]+){3,24}$/ [INT] => /^[0-9\-\+]+$/ [WORD] => /^[\w]+$/ [LETTER+SPACE] => /^[a-z _\-\:]+$/i ) [is_html_entity] => [fe_current_url] => http://example.com/index.php?category04_01_05 )
Interesting are here the two ranges $form['template'] and $form['template_copy'] those the finished email text contain.
Both texts are identical, for simplicity, but could also be different.
Name: Herr Franz Mustermann E-Mail: f-mustermann@example.com Nachricht: ------------------------------ Bitte geben Sie hier Ihre Nachricht ein ------------------------------ Sehr geehrter Herr Franz Mustermann, wir bedanken uns für das Interesse und werden uns in Kürze bei Ihnen melden. Mit freundlichem Gruß Sir-Oblong-Fitz-Oblong
The correct personal address was substitute with the help of the script at the placeholder [%TITLE%] in the emails To and CC.
This text is now correctly send as email.
File: template/inc_script/frontend_init/my_form_title_de.php
The correct personal address is spent in the e-mails To and CC.
<?php // ------------------------------------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day."); } // ------------------------------------------------------------------------------------------- /********************************************************************************************* Simple script for calling a PHP function from a form, after the submit The correct personal address is spent in the e-mails To and CC The e-mail text is displayed after a successful send Einfaches Script fur den Aufruf einer PHP-Funktion aus einem Formular heraus nach dem submit. Die richtige Anrede personenbezogen wird in den E-Mails To und CC ausgegeben Der E-Mailtext wird nach erfolgreichem senden ausgegeben 20.01.2009 K.Heermann http://planmatrix.de **********************************************************************************************/ /* ----------------------------------------------------- [Frau] Sehr geehrte Frau XXX [Herr] Sehr geehrter Herr XXX [Firma] Sehr geehrte Damen und Herren der Firma XXX ---------------------------------------------------------*/ // Function using in recipient template // Funktion fuer das "Empfaenger"-Template function my_form_title_recipient_de( &$postvar, &$form, &$mail ) { // Die richtige Anrede suchen // Set up the right title // --------------------------------------------------------------- $result = ''; switch (trim($postvar['title'])) { case 'Frau': $result = 'Sehr geehrte Frau '.trim($postvar['name']); break; case 'Herr': $result = 'Sehr geehrter Herr '.trim($postvar['name']); break; case 'Firma': $result = 'Sehr geehrte Damen und Herren'; break; default: $result = 'Sehr geehrte Damen und Herren'; } // Replace the form placeholder [%TITLE%] in both e-mail texts by the right title // Ersetzen des Formularplatzhalters [%TITLE%] in beiden E-Mailtexten durch die richtige Anrede // --------------------------------------------------------------- $form['template'] = str_replace('[%TITLE%]',$result, $form['template']); // recipient: / Empfaenger: // Output e-mail text // Ausgabe E-Mailtext // --------------------------------------------------------------- $email_text = '<div style="width:510px; padding:10px; margin:10px; border:1px dotted #666; background:#eee;">'; $email_text .= $form['template']; $email_text .= '</div>'; // More link // Weiter link $email_text .= '<div style="padding:20px 0 0 20px; font-weight:bold;">'; $email_text .= '<a href="'.$GLOBALS['content']["struct"][$GLOBALS['content']["cat_id"]]["acat_alias"].'.phtml">'; $email_text .=' >>Weiter >></a>'; $email_text .= '</div>'; // Insert e-mail text and if non HTML: convert LF to <br> // Einsetzen des E-Mailtextes und wenn kein HTML LF nach <br> $form['onsuccess'] .= ($form['template_format'] == 1) ? $email_text : nl2br($email_text); } // ==== End function // Function using in copy to template // Funktion fuer das "Kopie an" Template function my_form_title_copy_to_de( &$postvar, &$form, &$mail ) { // Die richtige Anrede suchen // Set up the right title // --------------------------------------------------------------- $result = ''; switch (trim($postvar['title'])) { case 'Frau': $result = 'Sehr geehrte Frau '.trim($postvar['name']); break; case 'Herr': $result = 'Sehr geehrter Herr '.trim($postvar['name']); break; case 'Firma': $result = 'Sehr geehrte Damen und Herren'; break; default: $result = 'Sehr geehrte Damen und Herren'; } // Replace the form placeholder [%TITLE%] in both e-mail texts by the right title // Ersetzen des Formularplatzhalters [%TITLE%] in beiden E-Mailtexten durch die richtige Anrede // --------------------------------------------------------------- $form['template_copy'] = str_replace('[%TITLE%]',$result, $form['template_copy']); // copy to: / Kopie an: } // ==== End function ?>