This is an old revision of the document!


Inner field calculation

FIXME translate

http://forum.phpwcms.org/viewtopic.php?p=111914#p111914

Re: Kann man mit Formularfeldern rechnen?

Posted by Oliver Georgi on Tue Dec 16, 2008 18:30
Ein einfacher Weg so etwas zu realisieren, ist die Nutzung von (ganz exemplarisch):

a) 1 x hidden Feld (hidden_field_name) im Formular → das ist das Ziel der Berechnung und kann demzufolge dann als Wert in das Mailformular übernommen werden. b) dazu dann ein frontend_init Script “my_form_init.php”:

 if(isset($_POST['fieldname'])) {
  // hier die Berechnung durchführen - an der Stelle ganz beispielhaft realisiert.
  $_POST['hidden_field_name'] = xss_clean($_POST['fieldname']) * 1000;
}




Example 01

I'm setting up a site for a customer who will add a lot of articles describing different products. I don't want him(my customer) to set up a form for every product.
I want to “call” a form from the template with some sort of identification of the current article.

This is described also a thousand times inside the forum - working like “send a friend”.
Use an article with content part based on your needs outside public access.
Then use {SHOW_CONTENT:CP,ID} (ID = ID of the content part form) inside of your template.
It's no “out of the box” solution - but as I said it is discussed somewhere here in the forum.

Finish

FIXME translate

Create the file /template/inc_script/frontend_init/check.php
<?php
if(isset($_POST['eingabe'])) {
  // do your calculation here - this is an example.
  $_POST['versteckt'] = xss_clean($_POST['eingabe']) * 1000;
}
?>
Now you can do your calculations.
In our example the field input is multiplied by 1000, while the output is showing the input value and the result.

Insert a default for the hidden field (hidden). Define this field as “required”.
(If an error is encountered, set the field value to ”” ($_POST['my_hidden_field'] = ””;) ).

Result: Error → if the value is validating, then the hidden field value will too contain the valid result.
english/phpwcms-system/article/contentparts/form/special-applications/inner-field-calculation.1242991308.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