PHP Order form

Hi everyone,

I’m looking for a point in the right direction. I just about to start my biggest coding project yet. (A Simple PHP Order form).

The client has suggested that they want a form for users to enter a reference code (from a catalog) of a product type how many items they want. It will generate a sub total. And if the total is over a certain amount discount will be given.

The form will also have the regular form fields as well. e.g Name, email, address etc…

Then all this will post to a email. I’ve created contact form scripts before. But is there any links or tutorials that could help me do this or even point me in the right direction.

Thanks for all the help

Barry

Hi Barry, here is a form you can build on:
[php]

<?php // check if form has been submitted if(isset($_POST['submit'])) { // initialise an error array $errors = array(); // check the item is not empty if(!empty($_POST['item'])) { $item = $_POST['item']; } else { $item = false; $errors[] = 'Please enter an item'; } // check the amount is a number if(is_numeric($_POST['amount'])) { $amount = $_POST['amount']; } else { $amount = false; $errors[] = 'Please enter an amount'; } // check everything is ok if($item && $amount) { // set the item price (this is a dummy price, you will use the proper price stored elsewhere!) $itemPrice = 14.99; // how much is the total cost? $totalPrice = $itemPrice * $amount; // how much to spend before discount applied $discountTarget = 35.00; // set the discount at 10 percent of total price $discount = .10; // check if the total price exceeds the discount target price if($totalPrice > $discountTarget) { // if so, set the discount $discountSaved = number_format($totalPrice * $discount, 2); $discountPrice = number_format($totalPrice - ($totalPrice * $discount), 2); } else { // if not, set the normal price $discountPrice = $totalPrice; } // show how much to pay? echo 'Original price: £' . $totalPrice; echo '
'; echo 'Discount: £' . $discountSaved; echo '
'; echo 'Discount price: £' . $discountPrice; } else // something wasn't right? { // show the errors (if any) foreach($errors AS $error) { echo '

' . $error . '

'; } } } else { // display the form in HTML ?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
	Item: <input type="text" name="item" />
	Amount: <input type="text" name="amount" />
	<input type="submit" name="submit" value="Submit" />
</form>
<?php

} // close if/else statement
?>
[/php]

Based on the price i’ve put in the script, and wanting to purchase 4 items, this outputs:
[sup]Original price: £59.96
Discount: £6.00
Discount price: £53.96
[/sup]
Hope this helps :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service