Jump to content

Recommended Posts

Hi,

 

I'm trying to make an online order form

 

http://www.bulletproofwebdesign.co.uk/orderform/calculator.php

 

I want it to be like this one

 

http://www.dyn-web.com/code/order_form/example1.php#

 

So that the user can't choose the price, just the quantity.

 

How can I add that to my code?

 

<?php # Script 3.10 - calculator.php #5

$page_title = 'Digital Studio Cost Calculator';
include ('includes/header.html');

/* This function calculates a total
and then returns the results. 
The $tax argument is optional (it has a default value). */
function calculate_total ($qty, $cost, $tax = 0) {


$total = ($qty * $cost);
$taxrate = ($tax / 100); // Turn 5% into .05.
$total += ($total * $taxrate); // Add the tax.

return number_format($total, 2);

} // End of function.

// Check for form submission:
if (isset($_POST['submitted'])) {

// Minimal form validation:
if ( is_numeric($_POST['quantity']) && is_numeric($_POST['price']) ) {

	// Print the heading:
	echo '<h1>Total Cost</h1>';

	// Call the function, with or without tax:
	if (is_numeric($_POST['tax'])) {
		$sum = calculate_total ($_POST['quantity'], $_POST['price'], $_POST['tax']);
	} else {
		$sum = calculate_total ($_POST['quantity'], $_POST['price']);
	}

	// Print the results:
	echo '<p style="font-weight: bold; color: #C00">The total cost of purchasing ' . $_POST['quantity'] . ' business card(s) at £' . number_format ($_POST['price'], 2) . ' each, is £' . $sum . '.</p>';

} else { // Invalid submitted values.
	echo '<h1>Error!</h1>
	<p class="error">Please enter a valid quantity and price.</p>';
}

} // End of main isset() IF.

// Leave the PHP section and create the HTML form:
?>
<h1>Digital Studio Online Order Form</h1>
<form action="calculator.php" method="post">
<p>Quantity: <input type="text" name="quantity" size="5" maxlength="5" value="<?php if (isset($_POST['quantity'])) echo $_POST['quantity']; ?>" /></p>
<p>Price: <input type="text" name="price" size="5" maxlength="10" value="<?php if (isset($_POST['price'])) echo $_POST['price']; ?>" /></p>
<p><input type="submit" name="submit" value="Calculate!" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php // Include the footer:
include ('includes/footer.html');
?>

Link to comment
https://forums.phpfreaks.com/topic/205422-php-order-form/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.