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

Erstelle dir die Datei /template/inc_script/frontend_init/check.php
<?php
if(isset($_POST['eingabe'])) {
  // hier die Berechnung durchführen - an der Stelle ganz beispielhaft realisiert.
  $_POST['versteckt'] = xss_clean($_POST['eingabe']) * 1000;
}
?>
Jetzt kannst du deine Berechnungen durchführen.
Zur Zeit wird der Inhalt des Feldes “eingabe” mit 1000 multipliziert, angezeigt wird der Eingabewert und das Ergebnis.

Dem versteckten Feld (hidden) einen Standardwert mitgeben. Das Feld als Pflichfeld im CP definieren.
(Bei Fehler in der Berechnung Feldwert auf ”” ($_POST['my_hidden_field'] = ””;) setzen).

Ergebnis: Fehlermeldung → ist das Ergebnis gültig, hat auch der hidden Feldwert das gültige Ergebnis.
english/phpwcms-system/article/contentparts/form/special-applications/inner-field-calculation.1240639598.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