Zuerst eine leere php-Datei "kalkulation.php" erstellen in template/inc_script/frontend_init
Beispiel 1: Formular-Felder addieren.
5 Felder: wert1, wert2, wert3, wert4, wert5
1 Feld hidden: total
Kalkulation.php:
Code: Select all
<?php
if(isset($_POST)) {
$ans1 = $_POST['wert1'];
$ans2 = $_POST['wert2'];
$ans3 = $_POST['wert3'];
$ans4 = $_POST['wert4'];
$ans5 = $_POST['wert5'];
$_POST['total'] = $ans1 + $ans2 + $ans3 + $ans4 + $ans5;
}
?>
Beispiel 2: Formularfelder multiplizieren
1 Feld (unbedingt sicherstellen dass nur Zahlen akzeptiert werden): anzahl_fotos
1 Feld hidden (hier den Preis pro Stueck als default eingeben): preis_foto
1 Feld hidden: total
Kalkulation.php:
Code: Select all
<?php
// Formular was sent
if(isset($_POST['anzahl_fotos'])) {
// Calculation here...
$_POST['total'] = xss_clean($_POST['anzahl_fotos']) * xss_clean($_POST['preis_foto']);
}
?>