Price calculator form
What would be the correct way to create a site that incorporated a form as in the attachment that allows a customer to click on a few options in dropdown lists and checkboxes to give a final cost?
What would be the correct way to create a site that incorporated a form as in the attachment that allows a customer to click on a few options in dropdown lists and checkboxes to give a final cost?
you would need to hand code the calculation
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
$var1 = (isset($_POST['element1']))?intval($_POST['element1']):0;
$var2 = (isset($_POST['element2']))?intval($_POST['element2']):0;
$theSum = ($var1 + $var2);
echo $theSum;
}
?>
1. Ah, so am I correct in assuming this would not need a simple database and a backend to input values for the calculation to work. Its all done in the form.
2. Can you point me to some extra info on this so I can understand how its done.
no, no database is needed.
the calculation is done using basic math in php.
look at my example.
In my example, i am using 2 form elements. element1 and element2:
<input type="text" name="element1" id="element1" />
<input type="text" name="element2" id="element2" />
this line casts the value of element1 to a variable named var1 (it assigns 0 if the value is blank):
$var1 = (isset($_POST['element1']))?intval($_POST['element1']):0;
this line casts the value of element2 to a variable named var2 (it assigns 0 if the value is blank):
$var2 = (isset($_POST['element2']))?intval($_POST['element2']):0;
this line adds the 2 together using simple addition:
$theSum = ($var1 + $var2);
see this page for basics on PHP math:
php_operators.asp
Thankyou, clear and simple explanations, as always.
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
These out-of-the-box solutions provide you proven, tested applications that can be up and running now. Build a store, a gallery, or a web-based email solution.