Jump to content

Recommended Posts

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

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

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.

Link to comment
https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167528
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167545
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167551
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167584
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167604
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167783
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/226157-php-order-form/#findComment-1167832
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.