NAVIGATION
This shows you the differences between two versions of the page.
|
english:phpwcms-system:article:contentparts:form:special-applications:php-function-include [2010/02/04 07:45] Knut Heermann (flip-flop) |
english:phpwcms-system:article:contentparts:form:special-applications:php-function-include [2018/06/03 18:09] (current) |
||
|---|---|---|---|
| Line 5: | Line 5: | ||
| - | 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. | + | 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. //(Also, the transmission destination (email address) may be changed)//. |
| + | **These changes are not recorded in the database, because the values were written into the database before the function is called.** | ||
| + | |||
| + | \\ | ||
| 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 call must be registered in the form in the fields “php function:” below **"recipient template:"** or **"copy to - template:"**. //(See picture below)//. | ||
| Line 46: | Line 49: | ||
| [Firma] "Sehr geehrte Damen und Herren" | [Firma] "Sehr geehrte Damen und Herren" | ||
| - | In addition, the dispatches e-mail will be displays again after the "send" //(submit)//. | + | In addition, the dispatched e-mail will be displayed again after the "send" //(submit)//. |
| - BE: In the templates for To //"recipient - template"// and CC //"copy to - template"// a placeholder [%TITLE%] is used for the address. | - BE: In the templates for To //"recipient - template"// and CC //"copy to - template"// a placeholder [%TITLE%] is used for the address. | ||
| Line 64: | Line 67: | ||
| ===== Frontend-Output ===== | ===== Frontend-Output ===== | ||
| - | The corrected e-mail will be spent and delivered. | + | The corrected e-mail will be presented and delivered. |
| Line 148: | Line 151: | ||
| ===== Digression Functions / Variables ===== | ===== Digression Functions / Variables ===== | ||
| - | First the function for **"recipient - template ** //(" my_form_title_recipient_de ")// and in a second call the function for **"copy to - template** //( "my_form_title_copy_to_de")// is processed. At the order we have no control. | + | First the function for **"recipient - template ** //(" my_form_title_recipient_de ")// and in a second call the function for **"copy to - template** //( "my_form_title_copy_to_de")// is processed. At this time we cannot control the order. |
| A function call will be autom. pass the three arrays **$postvars, $form** and **$mail** //(see below)//. | A function call will be autom. pass the three arrays **$postvars, $form** and **$mail** //(see below)//. | ||
| Line 154: | Line 157: | ||
| **Example:** \\ | **Example:** \\ | ||
| - | The function call from the form with **"my_incredible_function"** expects the function | + | The function call from the form with **"my_incredible_function"** is expecting the function |
| function my_incredible_function( &$postvar, &$form, &$mail ) { .... } | function my_incredible_function( &$postvar, &$form, &$mail ) { .... } | ||
| - | in a file at the folder **template/inc_script/frontend_init/ ** | + | in a file within the folder **template/inc_script/frontend_init/ ** |
| Line 164: | Line 167: | ||
| These texts can be read, manipulated and written back now by php. \\ | These texts can be read, manipulated and written back now by php. \\ | ||
| - | After the functions were left the emails to the registered addresses are sent. | + | After processing of the functions the emails are sent to the registered addresses. |
| The database is already filled before calling the function, here the manipulated result is not recorded. | The database is already filled before calling the function, here the manipulated result is not recorded. | ||
| + | ==== Test script: ==== | ||
| + | |||
| + | ---- | ||
| + | \\ | ||
| + | **File:** template/inc_script/frontend_init/form_test.php | ||
| + | |||
| + | **Condition:** $phpwcms['allow_ext_init'] = 1; -> [[http://www.phpwcms-docu.de/conf_inc_php_en.phtml|/config/phpwcms/conf.inc.php]] \\ | ||
| + | |||
| + | <code php|h form_test.php |h> | ||
| + | <?php | ||
| + | /********************************************************************************************/ | ||
| + | /** | ||
| + | * Script for the function of the form | ||
| + | * | ||
| + | * 17.03.2010 (c) K.Heermann http://planmatrix.de | ||
| + | */ | ||
| + | /********************************************************************************************/ | ||
| + | // ------------------------------------------------------------------------------------------- | ||
| + | // obligate check for phpwcms constants | ||
| + | if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day."); } | ||
| + | // ------------------------------------------------------------------------------------------- | ||
| + | |||
| + | |||
| + | /** For testing form function | ||
| + | =============================================================================== | ||
| + | =============================================================================== | ||
| + | */ | ||
| + | function form_test( &$postvar, &$form, &$mail ) { | ||
| + | |||
| + | echo '<br>===== postvar ===========================<br>'; | ||
| + | dumpVar($postvar); | ||
| + | |||
| + | echo '<br>===== form ==============================<br>'; | ||
| + | dumpVar($form); | ||
| + | |||
| + | echo '<br>===== mail ==============================<br>'; | ||
| + | // Security risk if you forgot to remove the script after finishing work. | ||
| + | // Is also unattractive for most applications. | ||
| + | // dumpVar($mail); | ||
| + | echo '<br>===== mail ende =========================<br>'; | ||
| + | |||
| + | } // ==== End function | ||
| + | /* | ||
| + | =============================================================================== | ||
| + | =============================================================================== | ||
| + | */ | ||
| + | |||
| + | ?> | ||
| + | </code> | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | \\ | ||
| Line 177: | Line 235: | ||
| <code php>dumpVar($postvar);</code> | <code php>dumpVar($postvar);</code> | ||
| + | |||
| + | |||
| + | |||
| + | <note> | ||
| + | **$postvar** is spent only if ##[X] save form results ## is turned on, because you see the already stored data from the DB. \\ | ||
| + | A change in this data is not possible //(has no effect on the DB or the dispatch results)//. | ||
| + | </note> | ||
| <code php>function my_form_id( &$postvar, &$form, &$mail ) { dumpVar($postvar); } </code> | <code php>function my_form_id( &$postvar, &$form, &$mail ) { dumpVar($postvar); } </code> | ||
| Line 440: | Line 505: | ||
| === $form['template'] and $form['template_copy'] === | === $form['template'] and $form['template_copy'] === | ||
| - | Interesting are here the two ranges $form['template'] and $form['template_copy'] those the finished email text contain. | + | Of interest are the two ranges $form['template'] and $form['template_copy'], they are containing the processed email text. |
| Both texts are identical, for simplicity, but could also be different. | Both texts are identical, for simplicity, but could also be different. | ||
| Line 469: | Line 534: | ||
| </file> | </file> | ||
| - | The correct personal address was substitute with the help of the script at the placeholder ##[%TITLE%]## in the emails To and CC. | + | The correct personal address was substituted with the help of the script by the placeholder ##[%TITLE%]## in the emails To and CC. |
| - | This text is now correctly send as email. | + | This text is now correctly sent as email. |
| \\ | \\ | ||
| Line 599: | Line 664: | ||
| </code> | </code> | ||
| + | \\ | ||
| + | |||
| + | |||
| + | ===== Output of the email text (To) on the following page after sending ===== | ||
| + | |||
| + | The BE field "on success:" is filled in the script with the e-mail text from To (recipient - template) of the **variable $form['template']**. | ||
| + | To do this we write the text, wrapped into a little formatting, from **$form['template']** into the **variable $form['onsuccess']**. \\ | ||
| + | Moreover, is still a link //(more)// generated at current page //(form)//. | ||
| + | |||
| + | \\ | ||
| + | \\ | ||
| + | |||
| + | ====== Use of the i18n @@Replacementtags@@ in e-mails, for multilingual sides ====== | ||
| + | |||
| + | The process described above can be very simply used to translate e-mail text using the i18n function [[english/phpwcms_replacer_rts/integrated-tags/language-tags/i18n]] of phpwcms. | ||
| + | |||
| + | Assuming we'll write the following e-mail template: | ||
| + | |||
| + | @@Company@@: {company} \\ | ||
| + | @@Subject@@: {subject} | ||
| + | |||
| + | and want to have @@Company@@ for German e-mail recipient //(e.g. for the email copy)// as "Firma" and/or @@Subject@@ as "Betreff" in the e-mail stands for. | ||
| + | |||
| + | |||
| + | |||
| + | Then the following simple function helps: | ||
| + | |||
| + | <code php> | ||
| + | function email_i18n_substitute_text(&$postvar, &$form, &$mail){ | ||
| + | $form['template'] = i18n_substitute_text($form['template']); | ||
| + | $form['template_copy'] = i18n_substitute_text($form['template_copy']); | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | \\ | ||
| + | |||
| + | **email_i18n_substitute_text** must be registered as function in backend/form cp as described above. \\ | ||
| + | |||
| + | Naturally also the appropriate language file must be translated additionally. | ||
| + | \\ | ||
| + | \\ | ||