Jump to content

php order form


j05hr

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.