close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Price calculator form

Thread began 11/14/2012 10:30 am by bill3786 | Last modified 11/14/2012 11:41 am by bill3786 | 5090 views | 4 replies |

bill3786

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?

Sign in to reply to this post

Jason ByrnesWebAssist

you would need to hand code the calculation


php:
<?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;
}
?>
Sign in to reply to this post

bill3786

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.

Sign in to reply to this post

Jason ByrnesWebAssist

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

Sign in to reply to this post

bill3786

Thankyou, clear and simple explanations, as always.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

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.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...