Forum Moderators: coopster

Message Too Old, No Replies

Order form - POSTING selected fields only

Passing orderform data to next page for confirmation

         

michlcamp

5:23 am on Jul 16, 2005 (gmt 0)

10+ Year Member



I have an orderform with nine product items which is created from a database of those products. One of the fields created is a Quantity field (qty) that allows the user to enter how many of each product they want to purchase.

I want to post the order to the next .php page where the items will show on a final orderform with $price * $qty = $totalprice but want to send only the products where a quantity has been entered on the previous page.

I'm looking for code to include that will assist with that.
All responses appreciated.
thanks in advance.

grandpa

5:36 am on Jul 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I understand that you want to send only the products where a quantity has been entered on the previous page. However, it may be lots easier to send all of the items, and then on the next page perform your calculations only where the quantity is greater than zero.

Otherwise, you may need to use javascript on the first page to loop thru the form and send only the desired items.

<add>

To POST to the next page you'll need this on your form.
<form action="http://www.example.com/your_page.php" method="post">

Then on your_page.php you'll need to access the POST variables. Here's one method.

while(list($key, $value) = each($HTTP_POST_VARS))
{
if ($key == 'VAL1') {
$val1 = $value;
}
if ($key == 'VAL2') {
$val2 = $value;
}

The variables VAL1, VAL2, etc are the input variables on your form. The variables $val1, $val2, etc can be used in you php script.

</add>

michlcamp

5:46 am on Jul 16, 2005 (gmt 0)

10+ Year Member



Want to stay away from java if I can - these are medical products and not all the visitors have java enabled, for whatever reason.

The other problem (but if I can fix it your idea works fine) is that the qty fields that nothing was entered into all post to the next page as zero values - "0.00" and I haven't been able to just return a blank field. Any thoughts on that appreciated as well.
thanks.

grandpa

5:54 am on Jul 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hmmm, are you saying that on the second page you want to display a blank instead of 0.00? I will usually use a second variable when I want to do that, which is what actually gets displayed. Perform a test on the original and assign the second variable. The original variable can also be assigned a blank value if it is equal to 0.00. My personal preferance is not to change values, I might want to check it again..

<$php
if ($var1 == '0.00') {
$tempvar = ' ';
}
else {
$tempvar = $var1;
}

echo "$tempvar";
?>

And, Welcome to WebmasterWorld!

michlcamp

6:55 am on Jul 16, 2005 (gmt 0)

10+ Year Member



ok, that's going to come in handy - but here's why I think I have the 0.00 problem:

I'm calculating $qty * $price with this code:

<?php printf ("%01.2f", $_POST['Complete_Set']* $_POST['price_Complete_Set']);?>

is my problem with the printf variables?

I tried this and it works as well, but still renders the 0.00 instead of " "

<?php printf ("%01.2f", $tempvar * $_POST['price_Complete_Set']);?>

Thanks again,
mc

grandpa

9:19 am on Jul 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It appears that you are formatting the result of the equation, so you will always return 0.00 instead of blank. You can condition the printf statement like this..

<?php

if ($var1 > 0) {
printf ("%01.2f", $var1 * $_POST['price_Complete_Set']);
}
else {
echo " ";
}

?>

Now, you really don't need $tempvar like I showed earlier, because you aren't changing it to a blank value for printing. At this point it just clutters things up... use the correct variable from your POST instead.

michlcamp

5:15 pm on Jul 16, 2005 (gmt 0)

10+ Year Member



Thanks...that worked great.
Now I have one more question here...
(and by now you can see that I'm learning by experment)

I'd like to exclude an HTML table row from being printed based on whether or not a quantity for that item has been entered. Something like this (but this doesn't work)

<? if ($var3 > 0) {echo
"<tr>
<td width=60><?php if ($var3 > 0) {printf ("%01.2f", $price3);}else {echo " ";}?></td>

<td WIDTH=40><?php if ($var3 > 0) {printf ("%01.2f", $var3 * $price3);}else {echo " ";}?> </td>
</tr>"
;}?>

Any suggestions there?
many thanks for your expertise and time.
mc

ergophobe

7:50 pm on Jul 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The multiple "ifs" all testing the same condition are redundant


<?
if ($var3 > 0)
{
echo "<tr><td>";
printf ("%01.2f", $price3);
echo "</td><td>";
printf ("%01.2f", $var3 * $price3);
echo "</td></tr>";
}
?>

I know this is the PHP forum, but FYI... Ideally you should
- quote all attributes in HTML
- specify widths with CSS rather than HTML

michlcamp

9:11 pm on Jul 16, 2005 (gmt 0)

10+ Year Member



That did it..thanks a lot.
(I do spec the HTML stuff in CSS, thanks)

many thanks!
mc

ergophobe

9:16 pm on Jul 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



many welcomes ;-)