View Full Version : PHP Confirmation Page
viper102464
06-09-2006, 07:39 PM
Hello all, im really new to php, i know a couple of basic things, but thats about it. I am making a page where you can build a custom computer and when you click the Build button, it takes you to a page that pretty much displays all of the information you selected on the previous page, confirming your order. My page is here:
http://www.oharanetworks.com/jcr/build/test.htm
When you click build, I have a simple php page that i want to display the actual name of the processor as on the previous page, but I can only get it to display the value on the page. Im using this
<?php echo $_GET["processor"]; ?>
But I want to get it to say the name of the processor too, not just the price.
Anyhelp is requested. Thank you in advanced.
viper102464
06-09-2006, 08:53 PM
No one knows how to display form data on another page using "get" method? Help please.:confused: :confused:
Using your operating systems as an example, because there are comfortably few and I want to make a point, I suggest you do something like this:
<select size="1" name="os" onchange="this.form.c14.value=this.options[this.selectedIndex].value;calculate()">
<option selected value="os0">Microsoft Windows XP Professional w/ SP2 [Included in Price]</option>
<option value="os1">Microsoft Windows XP Home Edition w/ SP2 [Subtract $45]</option>
<option value="os2">Gentoo Linux [Subtract $125]</option>
<option value="os3">Fedora Core 5 [Subtract $130]</option>
<option value="os4">No OS [Subtract $135]</option>
</select>Then, in your PHP:
$oses = array(
"os0" => array(
"name" => "Microsoft Windows XP Professional Edition SP2",
"price" => 135.0
),
"os1" => array(
"name" => "Microsoft Windows XP Home Edition SP2",
"price" => 90.0
),
"os2" => array(
"name" => "Gentoo Linux",
"price" => 10.0
),
"os3" => array(
"name" => "Fedora Core 5",
"price" => 5.0
),
"os4" => array(
"price" =>"No OS",
"name" => 0.0
)
);
echo("OS: " . $oses[$_GET['os']]['name'] . " (\$" . $oses[$_GET['os']]['price'] . ");");You really ought to include some non-Windows OSes in there, and a no-OS option.
viper102464
06-11-2006, 07:37 AM
Great Idea! Thanks for all your help!:) :)
But there is only one problem, I need to have the price of the OS in the "value" section of the drop down box in order for the calculator to work.
I have no idea how to fix this, all help is welcomed. Thanks again though.
djr33
06-11-2006, 08:39 AM
<option value="135">No OS [Subtract $135]</option>
...?
viper102464
06-11-2006, 07:25 PM
Yes, but if i put the price as the value, the calculator will work, but then twey's code no longer works because the values are no longer os0, os1, os2, os3, and os4, they are different prices. Thus the php will no longer work. I need the calculator and the php script to both work. That's what i was unsure how to do.
Thanks, and please help.:confused:
Hm... it's tricky. You could pass the price as the value, but then it becomes confusing if you have two items with the same price.
I suggest you modify the calculator. Post it here and we'll have a butcher's.
viper102464
06-12-2006, 02:26 AM
Here is the calculator script that jscheuer1 helped me with:
<script language="javascript">
function cent(amount) { return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount); } function calculate() { var p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14; p1 = xseven.c1.value * 1; p2 = xseven.c2.value * 1; p3 = xseven.c3.value * 1; p4 = xseven.c4.value * 1; p5 = xseven.c5.value * 1; p6 = xseven.c6.value * 1; p7 = xseven.c7.value * 1; p8 = xseven.c8.value * 1; p9 = xseven.c9.value * 1; p10 = xseven.c10.value * 1; p11 = xseven.c11.value * 1; p12 = xseven.c12.value * 1; p13 = xseven.c13.value * 1; p14 = xseven.c14.value * 1; total_price = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11 + p12 + p13 + p14; xseven.total_price.value = cent(Math.round(total_price*Math.pow(10,2))/Math.pow(10,2)); } </script>
And here is the code for one of the drop down boxes:
<select size="1" name="processor" onchange="this.form.c3.value=this.options[this.selectedIndex].value;calculate()">
<option value="639.00">AMD Athlon 64 FX55 San Diego 2000MHz HT Socket 939 [Subtract $172] </option>
<option value="811.00" selected>AMD Athlon 64 FX57 San Diego 2000MHz HT Socket 939 [Included in Price] </option>
<option value="853.00">AMD Athlon 64 FX60 Toledo 2000MHz HT Socket 939 Dual Core [Add $42] </option>
</select>
I used hidden values for the initial prices of all the items so that it would already have an initial price calculated.
Thanks again for all of your help!:)
djr33
06-12-2006, 06:17 AM
You could just have a bunch of ifs:
<?php
if ($_GET['thing'] == "thing") {
$price = 135;
}
elseif (.....
?>
Something like that, and just repeat for each item.
Drop the client-side calculation routine. You say John wrote this? It certainly doesn't look like his style -- and that's a compliment to him.
Your PHP script:
<?php
function toCurrency($amount) {
$amount *= 100;
$amount = round($amount);
$amount /= 100;
if(strpos($amount, ".") === false)
return $amount . ".00";
while(strlen(substr($amount, ".")) < 2)
$amount .= "0";
return $amount;
}
function getSelectedItems($items) {
$si = array();
foreach($_GET as $k => $v)
if(isset($items[$v])) array_push($si, $items[$v]);
return $si;
}
function formatItemList($items) {
$si = getSelectedItems($items);
$rt = 0;
$html = "<table><tr><th>Item</th><th>Price</th><th>Running Total</th></tr>";
for($i = 0; $i < count($si); ++$i)
$html .= "<tr><td>" . $si[$i]['name'] . "</td><td>" . $si[$i]['price'] . "</td><td>" . ($rt += $si[$i]['price']) . "</tr>";
$html .= "<tr><td>Total</td><td>$rt</td><td>$rt</td></tr></table>";
}
$items = array(
"os0" => array(
"name" => "Microsoft Windows XP Professional Edition SP2",
"price" => 135.0
),
"os1" => array(
"name" => "Microsoft Windows XP Home Edition SP2",
"price" => 90.0
),
"os2" => array(
"name" => "Gentoo Linux",
"price" => 10.0
),
"os3" => array(
"name" => "Fedora Core 5",
"price" => 5.0
),
"os4" => array(
"name" =>"No OS",
"price" => 0.0
),
"cpu0" => array(
"name" => "AMD Athlon 64 FX55 San Diego 2000MHz HT Socket 939",
"price" => 639.0
),
"cpu1" => array(
"name" => "AMD Athlon 64 FX57 San Diego 2000MHz HT Socket 939",
"price" => 811.0
),
"cpu2" => array(
"name" => "AMD Athlon 64 FX60 Toledo 2000MHz HT Socket 939 Dual Core",
"price" => 853.0
)
// Add more. Doesn't matter what the names are, so long as they match the values on the form.
);
echo(formatItemList($items));
?>Has the added advantage of being easier to convert to using a database when you decide to do this properly. :)
Untested.
viper102464
06-13-2006, 01:31 AM
Thanks for the script, but does it go on the main page, with all of the item drop down boxes, or on the mail.php page? Because I cannot get it to work.:confused: Sorry, im really new to all of this. I wanted the calculator to work though still, because I want my clients to be able to see their running total WHILE they are choosing there items. I thought java script was the best way to do this. Im sure this is possible to do, but I have no clue how to do it. Thanks djr33 for the tip, if nothing else works, I guess i might have to do that, im just trying to save as much time possible.
Thanks twey, but could you help me a bit more on this script please?:)
Here's what I threw together. Uses Mike's slightly-famed Number.toCurrency() function.
<?php
// test.php
function toCurrency($amount) {
$amount *= 100;
$amount = round($amount);
$amount /= 100;
if(strpos($amount, ".") === false)
return $amount . ".00";
while(strlen(substr($amount, ".")) < 2)
$amount .= "0";
return $amount;
}
function getSelectedItems($items) {
$si = array();
foreach($_POST as $k => $v)
if(isset($items[$v])) array_push($si, $items[$v]);
return $si;
}
function formatItemList($items) {
$si = getSelectedItems($items);
$rt = 0;
$html = '<table style="text-align:center;"><tr><th>Item</th><th>Price</th><th>Running Total</th></tr>';
for($i = 0; $i < count($si); ++$i)
$html .= "<tr><td>" . $si[$i]['name'] . "</td><td>\$" . toCurrency($si[$i]['price']) . "</td><td>\$" . toCurrency($rt += $si[$i]['price']) . "</tr>";
$html .= "<tr style=\"font-weight:bold;\"><td>Total</td><td>\$" . toCurrency($rt) . "</td><td>\$" . toCurrency($rt) . "</td></tr></table>";
return $html;
}
$items = array(
"os0" => array(
"name" => "Microsoft Windows XP Professional Edition SP2",
"price" => 135.0
),
"os1" => array(
"name" => "Microsoft Windows XP Home Edition SP2",
"price" => 90.0
),
"os2" => array(
"name" => "Gentoo Linux",
"price" => 10.0
),
"os3" => array(
"name" => "Fedora Core 5",
"price" => 5.0
),
"os4" => array(
"name" =>"No OS",
"price" => 0.0
),
"cpu0" => array(
"name" => "AMD Athlon 64 FX55 San Diego 2000MHz HT Socket 939",
"price" => 639.0
),
"cpu1" => array(
"name" => "AMD Athlon 64 FX57 San Diego 2000MHz HT Socket 939",
"price" => 811.0
),
"cpu2" => array(
"name" => "AMD Athlon 64 FX60 Toledo 2000MHz HT Socket 939 Dual Core",
"price" => 853.0
)
// Add more. Doesn't matter what the names are, so long as they match the values on the form.
);
if(!isset($_POST['calculate'])) { ?>
<html>
<head>
<title>F</title>
<script type="text/javascript">
Number.prototype.toCurrency = function(c, t, d) {
// Mike Winter (mwinter)'s Number.toCurrency() function.
var n = +this,
s = (0 > n) ? '-' : '',
m = String(Math.round(Math.abs(n))),
i = '',
j, f;
c = c || '';
t = t || '';
d = d || '.';
while (m.length < 3) {m = '0' + m;}
f = m.substring((j = m.length - 2));
while (j > 3) {i = t + m.substring(j - 3, j) + i; j -= 3;}
i = m.substring(0, j) + i;
return s + c + i + d + f;
};
var items = new Object();
<?php foreach($items as $k => $v) { ?>
items['<?php echo($k); ?>'] = <?php echo(toCurrency($v['price']) * 100); ?>;
<?php } ?>
function calcTotal(frm) {
var total = 0;
for(var i=0; i<frm.elements.length; i++) {
if(typeof items[frm.elements[i].value] != "undefined")
total += items[frm.elements[i].value];
}
return total;
}
window.onload = function() {
for(var i=0;i<document.forms[0].elements.length;i++)
if(document.forms[0].elements[i].tagName.toLowerCase() == "select")
document.forms[0].elements[i].onchange = function() {
document.getElementById("ttl").innerHTML = calcTotal(this.form).toCurrency('$');
};
document.getElementById("ttl").innerHTML = calcTotal(document.forms[0]).toCurrency('$');
};
</script>
</head>
<body>
<form action="<?php echo($PHP_SELF); ?>" method="post">
<input type="hidden" name="calculate" value="true">
<select name="os">
<?php for($i = 0; isset($items["os$i"]); $i++) { ?>
<option value="os<?php echo($i); ?>"><?php echo($items["os$i"]['name']); ?> ($<?php echo(toCurrency($items["os$i"]['price'])); ?>)</option>
<?php } ?>
</select>
<br>
<select name="cpu">
<?php for($i = 0; isset($items["cpu$i"]); $i++) { ?>
<option value="cpu<?php echo($i); ?>"><?php echo($items["cpu$i"]['name']); ?> ($<?php echo(toCurrency($items["cpu$i"]['price'])); ?>)</option>
<?php } ?>
</select>
<br>
<p style="font-weight:bold;">
Total: <span id="ttl"></span>
<input type="submit">
</p>
</form>
</body>
</html>
<?php } else { ?>
<html>
<head>
<title>Confirmation Page</title>
</head>
<body>
<?php echo(formatItemList($items)); ?>
</body>
</html>
<?php } ?>It lacks your formatting and data, since I was merely experimenting. I'm sure you should have no trouble integrating it.
Marginally tested.
viper102464
06-13-2006, 09:24 PM
SWEET!!! Thats just what i needed. THANK YOU VERY MUCH. I appreciate it.:) :)
But, one last thing, I promise! How do I change the font of the listed items and prices on the confirmation page? Whenever I mess with the script, it no longer works, but that's probably because I dont know what the heck im doing.
If you could let me know how to change the font, that would be great. Thanks.
You can wrap the PHP blocks in a styled element just as you would with any other table.
Also, any of the HTML in the formatItemList() function can be edited easily enough, with the stipulation that you escape special characters such as double quotes and dollar signs.
viper102464
06-15-2006, 01:18 AM
Thanks again Twey. I have everything how I want it now, but now I need to email that confirmation page with the buyers name, credit card info and other information. How would I do that, using what you have already made?
I tried doing something like this, just to email myself the setup of the system, but I know it's completely wrong, here is a piece of it:
function confirm {
$to = "josh@oharanetworks.com";
$subject = "X-7000 Order";
$message = "<?php echo (formatItemList($items)); ?>";
$from = "someonelse@anotherplace.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
}
function getSelectedItems($items) {
$si = array();
foreach($_POST as $k => $v)
if(isset($items[$v])) array_push($si, $items[$v]);
return $si;
}
function formatItemList($items) {
$si = getSelectedItems($items);
$rt = 0;
$html = '<img src="../../images/PNG/logo_build_7000_confirmation.png"><br><table style="text-align:right; border-left:1px solid; border-right:1px solid; border-top:1px solid; border-bottom:1px solid;"><tr><th width="737">Item</th><th width="79">Price</th><th width="84">Running Total</th></tr>';
for($i = 0; $i < count($si); ++$i)
$html .= "<tr><td>" . $si[$i]['name'] . "</td><td>\$" . toCurrency($si[$i]['price']) . "</td><td>\$" . toCurrency($rt += $si[$i]['price']) . "</tr>";
$html .= "<tr><td></td></tr><tr><td></td></tr><tr><td><b>Total:</b></td><td>\$" . toCurrency($rt) . "</td></tr></table>";
return $html;
$html = '<form action="<?php function confirm?>" method="post"><input type="submit" name="submit" value="Confirm Order">';
}
What I was trying to do is link the "Confirm Order" button to the confirm function, but, as you can tell, I did it wrong, because it doesn't work.
Thanks again for your help, it is greatly appreciated!
Again, the working url is here: http://www.oharanetworks.com/jcr/build/7000/
Blank TDs won't display in some browsers. You should put " " inside them at least.
HTML outside the table (with particular attention to that image) would be better put here:
<?php } else { ?>
<html>
<head>
<title>Confirmation Page</title>
</head>
<body>
<?php echo(formatItemList($items)); ?>
</body>
</html>
<?php } ?>... where you can enter it in plain, nicely-formatted HTML.
The confirm function should look something like this:
function confirm() {
global $items;
$to = "josh@oharanetworks.com";
$subject = "X-7000 Order";
$message = formatItemList($items));
$from = "someonelse@anotherplace.com";
$headers = "From: $from";
mail($to, $subject, $message, $headers);
}
viper102464
06-21-2006, 05:28 AM
Thanks Twey for all of your help, that will work just fine.:) :)
Minus the extra bracket on the $message line, of course.
newgurl
06-29-2008, 05:27 AM
Hi I know this is an old discussion but can I please have some help with modifying this to suit my needs?
I like the running total and I would like to make quote/order form that will then email both of us the order total but then using a session go to the next form to get them to pay a deposit for the work.
Does that make sense?
Thanks...I am confusing myself at the moment.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.