# special calculation include file for Simple Form ########################################################################## ### THIS IS A SAMPLE FILE, based on form I use ### at worldcommunity.com ### Note that you can do things here like calculate subtotals, ### add to the display output, send totals over to a live ### credit card server, or display a PayPal button (see below) ########################################################################## # calculate subtotal, tax, shipping and grand total $unit_price = 14.95; $subtotal = 0; $va_tax = .05; $tax = 0; $shipping = 0; $grand_total = 0; # Since the main script does NOT create variables # for each form field, you need to re-grab calc field values # from the form here, and put them into variables # This also allows you to do extra validation here. $quantity = param('Quantity'); $virginia_yes_no = param('Virginia Yes/No'); if ( $quantity >= 1 and $quantity <= 9 ) { $unit_price = 14.95; } elsif ( $quantity >= 10 and $quantity <= 24 ) { $unit_price = 10.00; } elsif ( $quantity >= 25 ) { $unit_price = 9.00; } else { &error_message(qq~Error!

Quantity must be greater than zero.
Please hit BACK and try again. ~); } $subtotal = $quantity * $unit_price; if ( $virginia_yes_no eq 'Yes' ) { $tax = $subtotal * $va_tax; } # shipping # 1-4 copies: $1 each plus $2 # 5-10 copies: $10 # 11-25 copies: $20 # 26-50 copies: $25 # 51-100 copies: $35 if ( $quantity >= 1 and $quantity <= 4 ) { $shipping = ( $quantity * 1.00 ) + 2.00; } elsif ( $quantity >= 5 and $quantity <= 10 ) { $shipping = 10.00; } elsif ( $quantity >= 11 and $quantity <= 25 ) { $shipping = 20.00; } elsif ( $quantity >= 26 and $quantity <= 50 ) { $shipping = 25.00; } elsif ( $quantity >= 51 and $quantity <= 100 ) { $shipping = 35.00; } else { &error_message(qq~Alert!

This form only calculates shipping for orders of 1 to 100. For greater quantities, please email us at: you\@domain.com.

Thank you! ~); } $grand_total = sprintf("%.2f", $subtotal + $tax + $shipping ); ### NOTE: This is a good spot to insert some code to ### send the $grand_total over to a live credit card company ### (or you can use the PayPal button below) $subtotal = sprintf("%.2f", $subtotal); $tax = sprintf("%.2f", $tax); $shipping = sprintf("%.2f", $shipping); $unit_price = sprintf("%.2f", $unit_price); $paypal_form = qq~ To Complete Your Order
Either Click the "Pay with a Credit Card" Button Below
or Print Out This Page and Mail it to:
Some Address, City, State, Zip




~; # output and show paypal link $mail_body .= qq~ ------------------------------ Unit Price: $unit_price Subtotal: $subtotal Tax: $tax Shipping: $shipping Grand Total: $grand_total ------------------------------ ~; # we add output to the variable $html_text, # which has already been created in the main script # The text below will appear at the bottom of the # output table. $html_text .= qq~ Unit Price: $unit_price   Subtotal: $subtotal   Tax: $tax   Shipping: $shipping   Grand Total: $grand_total   ~; if ( $preview_data ne 'yes' ) { $html_text .= qq~ $paypal_form ~; } ########################################################################## 1;