barrycorrigan Posted January 30, 2011 Share Posted January 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/ Share on other sites More sharing options...
harristweed Posted January 30, 2011 Share Posted January 30, 2011 Sounds like AJAX is required! Big subject. Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167507 Share on other sites More sharing options...
cyberRobot Posted January 30, 2011 Share Posted January 30, 2011 Sounds like AJAX is required! Big subject. This can be done without AJAX...as long as you're ok with the page refreshing between steps. Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167516 Share on other sites More sharing options...
cyberRobot Posted January 30, 2011 Share Posted January 30, 2011 You could look into building a multi-stage form. The first step could ask for the reference code from the catalog and the quantity. They would submit the form to a PHP script that looks for the reference code in your database, calculates the sub total, and determines if the discount applies. After the user verifies that they entered the reference code correctly and they are happy with the price. You can then ask them for the other details (name, address, etc.). That form would be submitted to another PHP script to process everything and send out an e-mail. Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167528 Share on other sites More sharing options...
jcbones Posted January 30, 2011 Share Posted January 30, 2011 Most of that is pretty easy, and none of it *REQUIRES* Ajax. Ajax just makes it prettier. I suppose you can build the form. Couple of simple inputs. Quantity and Product, or maybe you want a page with pics of product and an "add to cart" link? <?php function productPricing($price, $quantity, $discount, $discount_over_amount = 0) { $cost = floatval($price) * intval($quantity); $discount = str_replace(array('.','%'),'',strval($discount)); return ($cost > $discount_over_amount) ? number_format($cost - ($cost * floatval('.' . $discount)),2) : number_format($cost,2); } $price = 10; $quantity = 10; $discount = 20; $amount_to_apply_discount = 100; echo 'Your product cost $' . $price . ' and you have ordered ' . $quantity . ' of them. This will cost you $' . productPricing($price,$quantity,$discount,$amount_to_apply_discount) . ' after all discounts are applied.'; ?> I'm sure there is an easier faster way, but this is off the cuff. Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167545 Share on other sites More sharing options...
barrycorrigan Posted January 30, 2011 Author Share Posted January 30, 2011 We had a meeting about the project on Friday. We tried to convince the client to have the form in a stage by stage process i.e cyberRobot comment. But they said no. Basically thy want a massive form (which they think customers will use!) So basically I need a simple calculator script that creates a total then the user will fill out the rest of a normal form that posts to a email. I know I will get there it's getting it working in my head first of what exactly I need to do.... Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167551 Share on other sites More sharing options...
cyberRobot Posted January 31, 2011 Share Posted January 31, 2011 Are there a lot of products in your database? If not you could load everything into the page and use JavaScript for the calculator part. Otherwise you'll probably need to look into AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167577 Share on other sites More sharing options...
jcbones Posted January 31, 2011 Share Posted January 31, 2011 Still don't know why you are stuck on Ajax. I wouldn't use Javascript for any calculations. Keep the calculations on the server, and away from the client. With javascript disabled, then no matter how cool the AJAX was integrated, the script wouldn't calculate anything. Take the data from the form, post it to the page, verify and sanitize your data, do your calculations, send the email. Once you have the PHP script up and running, you can build a second version with AJAX if you are so inclined. That way you have one pretty one, and one that users can use if they don't allow javascript. Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167584 Share on other sites More sharing options...
cyberRobot Posted January 31, 2011 Share Posted January 31, 2011 Still don't know why you are stuck on Ajax. I wouldn't use Javascript for any calculations. Keep the calculations on the server, and away from the client. With javascript disabled, then no matter how cool the AJAX was integrated, the script wouldn't calculate anything. Take the data from the form, post it to the page, verify and sanitize your data, do your calculations, send the email. Once you have the PHP script up and running, you can build a second version with AJAX if you are so inclined. That way you have one pretty one, and one that users can use if they don't allow javascript. I would imagine the customer will want to see the order calculation before completing their order. This would likely require a multi-stage PHP script, which would be my preferred method. But since barrycorrigan's client doesn't want a multi-stage solution, there might not be any other option except a JavaScript/AJAX solution. Of course, if the OP uses JavaScript/AJAX they'll probably want to also build a fallback solution if JavaScript is disabled or isn't available. That is if the OP has the resources required to build/maintain two solutions. Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167604 Share on other sites More sharing options...
barrycorrigan Posted January 31, 2011 Author Share Posted January 31, 2011 Basically there will be no database. The client is prepared to double check any orders that come through there email, So there will be three text boxes for the ref code price and quanity this will generate a total checks to see how much of a discount they are entitled to then post it to an email. Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167783 Share on other sites More sharing options...
cyberRobot Posted January 31, 2011 Share Posted January 31, 2011 So then the user types in the price? If so, then you should be able to create a PHP script as described by jcbones. Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167793 Share on other sites More sharing options...
barrycorrigan Posted January 31, 2011 Author Share Posted January 31, 2011 Would there be any links or tutorials to start or point me in the right direction. Becuase my knowledge of PHP is limited as far as creating contact forms etc etc.... Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167802 Share on other sites More sharing options...
cyberRobot Posted January 31, 2011 Share Posted January 31, 2011 After doing a quick Google search, this tutorial looks like it might help: http://www.htmlgoodies.com/beyond/webmaster/projects/article.php/3487836/A-Simple-Order-Form-Page.htm You can probably skip all the JavaScript stuff mentioned in the tutorial which will cut out a few steps. Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167832 Share on other sites More sharing options...
barrycorrigan Posted January 31, 2011 Author Share Posted January 31, 2011 cyberRobot that's perfect. How did I miss that. I was on the htmlgoodies site and seen a tutorial for an order form but wasn't this one. Wierd. But thanks for that link that will give me a good starting point :-) Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167852 Share on other sites More sharing options...
cyberRobot Posted January 31, 2011 Share Posted January 31, 2011 No problem; glad to help! Quote Link to comment https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167863 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.