hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : PHP order form?
Reply

Forum Jump

PHP order form?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-04-2002, 04:03 PM
vito vito is offline
Eternal Member
 
Join Date: Jan 2002
Location: Toronto, Canada
Posts: 11,059

PHP order form?


I want to set up an order form and I'm hoping PHP will help me achieve the following:

I have about 30 products, all identically priced. I want to have a form with a checkbox for each product where the customer checks off as many products as he wants to order. At 10 products, there is a discount. And at 20 products, there's another discount.

Is there a way with PHP to automatically calculate the total order cost based on how many products the customer selects?

Thanks for your help.

Vito

__________________
DemoDemo.com - Flash tutorials since 2002
DemoWolf.com - 5,300+ Flash tutorials for hosting companies, incl. Voice tutorials



Sponsored Links
  #2  
Old 09-04-2002, 06:42 PM
benoire benoire is offline
Registered User
 
Join Date: Jul 2001
Location: Coventry, England
Posts: 130
PHP Code:
--- orderform.php ---

<
input type="checkbox" name="product[]">Product A<br>
<
input type="checkbox" name="product[]">Product B<br>
<
input type="checkbox" name="product[]">Product C<br>
<
input type="checkbox" name="product[]">Product D<br>
<
input type="checkbox" name="product[]">Product E<br>
...

--- 
orderprocess.php ---

$totalproducts count($_POST['product']);
$productprice 5;

$discountfor10 5;
$discountfor20 10;

$discount = ($totalproducts >= 10 && $totalproducts 20) ? $discountfor10 : (($totalproducts 20) ? $discountfor20 0);

$total = ($productprice $totalproducts) - $discount
HTH


Last edited by benoire; 09-04-2002 at 06:48 PM.
  #3  
Old 09-04-2002, 06:54 PM
vito vito is offline
Eternal Member
 
Join Date: Jan 2002
Location: Toronto, Canada
Posts: 11,059
Thank you benoire. If you don't mind, I'd like to ask you to elaborate a bit. I'm really quite new at PHP. Actually, I'm quite pathetic at it...

You show input tags that are in orderform.php. Does it have to be a .php page? Can the code fall inside an HTML page? If so, do I put the opening and closing php tags around the form? In name="product[]", what do I replace? Just product? And leave the brackets?

And I'm not sure where to put that code for the orderprocess.php.

Sorry, I told you I really sucked at PHP...

Thanks very much for your help.

Vito

__________________
DemoDemo.com - Flash tutorials since 2002
DemoWolf.com - 5,300+ Flash tutorials for hosting companies, incl. Voice tutorials

Sponsored Links
  #4  
Old 09-04-2002, 07:07 PM
benoire benoire is offline
Registered User
 
Join Date: Jul 2001
Location: Coventry, England
Posts: 130
Heh, no problem, I guess I assumed you knew more than you do, not to worry

The names I gave each file were irrelevant... the name of the first one is entirely up to you, you can call it something.html if you want, I just tend to call all my pages .php for the sake of continuity, plus the fact that I tend to use PHP on every page anyway. The code I gave under 'orderform.php' is just your bogstandard HTML form, there is no PHP coding involved at this stage. Ensure that your form's <form action=""> tag points to somefilename.php - in this case I used orderprocess.php. The input tags should be part of the same form as the rest of the details that are required as part of placing the order.

The 'product[]' bits stay as they are - each textbox should be named 'product[]'. The reason for this is that when the data is passed on to the second page, you end up with a variable $product which is an array due to the fact that it contains many values - in this case, it contains 'TRUE' x times where x = number of checkboxes ticked.

The code in orderprocess.php goes in whichever page you post all your form data too. It can go anywhere, all it does is take the submitted checkbox data, counts the number of values in the array $product and then determines what the discount is based on this value. If you want to use a name other than product, simply change all the name="product[]" parts of orderform.php (or whatever you call it), and alter the $_POST['product'] part of orderprocess.php to $_POST['whatevernameyouchose'].

You'll no doubt have more code to put in orderprocess.php to email you the order or submit it to the database etc, this can go before or after the code I gave you.

Hope this helps clear things up a bit, if it doesn't, just say so and I'll try and explain things further

  #5  
Old 09-04-2002, 07:34 PM
vito vito is offline
Eternal Member
 
Join Date: Jan 2002
Location: Toronto, Canada
Posts: 11,059
benoire:

Thanks very much for taking the time to explain. I think I understand better. I will have a go at it, and let you know if I run into any problems.

Vito

__________________
DemoDemo.com - Flash tutorials since 2002
DemoWolf.com - 5,300+ Flash tutorials for hosting companies, incl. Voice tutorials

  #6  
Old 09-04-2002, 07:43 PM
benoire benoire is offline
Registered User
 
Join Date: Jul 2001
Location: Coventry, England
Posts: 130
Any time Just shout if you get stuck

  #7  
Old 09-04-2002, 08:16 PM
vito vito is offline
Eternal Member
 
Join Date: Jan 2002
Location: Toronto, Canada
Posts: 11,059
benoire:

Hmm. Actually I'm not sure this setup is going to work. You said that in my form it should read action="orderprocess.php". Obviously, that is in order to pass the info onto orderprocess.php to calculate totals. Problem: If all it's doing is passing totals, I have no way of knowing which products the customer wants to order.

Originally, I thought of just setting up a form using phpformmail, and when submitted, it would email me the contents of the form (a list of all the products checked off), and I would just put a redirect tag in the form to send the customer to page 2 in the ordering process. On the page 2, he would have to manually select whether he bought a 10-pack, a 20-pack, or whatever. Then when submitting, he would be taken into my cc processor's payment system.

That's the easiest way to do it. But then I'm relying on the customer to make the right selection on page 2. What I am trying to do instead is automatically display his order on page 2 (based on his selections on page 1), but I still need the particulars of the order emailed to me from page 1.

Does that make sense? Sorry if I wasn't more specific the first time around...

Vito

__________________
DemoDemo.com - Flash tutorials since 2002
DemoWolf.com - 5,300+ Flash tutorials for hosting companies, incl. Voice tutorials

  #8  
Old 09-04-2002, 08:42 PM
benoire benoire is offline
Registered User
 
Join Date: Jul 2001
Location: Coventry, England
Posts: 130
Good point, that's something I missed The way round this would be to use product[productname] instead of product[] in the name="" tags. Then on the orderprocess.php page, you could use the following code to get a list of products:

PHP Code:
$products $_POST['product'];

foreach (
$product as $key => $var) {
$productlist .= $product[$key]."\n";
}

$emailbody "Your email message in here with all your other data etc etc.\n\n".$productlist
Hopefully that should do the trick - but its 2am here and I'm rapidly reaching brain burnout time so I could have missed something

  #9  
Old 09-04-2002, 10:21 PM
vito vito is offline
Eternal Member
 
Join Date: Jan 2002
Location: Toronto, Canada
Posts: 11,059
Aaaaargh.

I appreciate your help, benoire, but I will have to use my original plan for now just to get the site functional. When it's running and I have time, I will come back to this thread and try again. I just couldn't get it to work properly.

Thanks again for your help. I'll be back, though...

Vito

__________________
DemoDemo.com - Flash tutorials since 2002
DemoWolf.com - 5,300+ Flash tutorials for hosting companies, incl. Voice tutorials

Reply

Related posts from TheWhir.com
Title Type Date Posted
Forget.me Makes Link Removal Process for Europe’s “Right to be Forgotten” Decision Even Easier Web Hosting News 2014-06-25 11:36:40
Box Nears Release of Customer-Held Encryption Key Product Web Hosting News 2014-04-02 13:14:44
ServInt Designs New Custom Shop Ordering System for Hosting Resellers Web Hosting News 2013-01-23 11:35:44
Lead Generation Part 2 – Content Syndication Blog 2012-12-12 12:37:59
Lead Generation Part 1 – Form Fills Blog 2012-11-16 09:03:48


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?