j05hr Posted June 21, 2010 Share Posted June 21, 2010 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/205422-php-order-form/ Share on other sites More sharing options...
Psycho Posted June 21, 2010 Share Posted June 21, 2010 Simple. Do NOT include the price on your order form as an input field. Just display it on the page as text Quote Link to comment https://forums.phpfreaks.com/topic/205422-php-order-form/#findComment-1075018 Share on other sites More sharing options...
j05hr Posted June 21, 2010 Author Share Posted June 21, 2010 So what would you put in there as the text to set the number? I know this doesn't work but this is my attempt just to show that I am trying to learn <p>Price: <?php $price = (10); /></p> Quote Link to comment https://forums.phpfreaks.com/topic/205422-php-order-form/#findComment-1075029 Share on other sites More sharing options...
Pikachu2000 Posted June 21, 2010 Share Posted June 21, 2010 $price = 10; echo "Price: " . $price; Quote Link to comment https://forums.phpfreaks.com/topic/205422-php-order-form/#findComment-1075031 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.